MySQL 8.0.39
Source Code Documentation
ha_archive.h
Go to the documentation of this file.
1/* Copyright (c) 2003, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#include <sys/types.h>
25#include <zlib.h>
26
27#include "my_dbug.h"
28#include "my_inttypes.h"
29#include "my_io.h"
30#include "sql/handler.h"
31#include "sql_string.h"
33
34/**
35 @file storage/archive/ha_archive.h
36 Archive storage engine.
37*/
38
39/*
40 Please read ha_archive.cc first. If you are looking for more general
41 answers on how storage engines work, look at ha_example.cc and
42 ha_example.h.
43*/
44
48};
49
51 public:
54 azio_stream archive_write; /* Archive file we are working with */
55 ha_rows rows_recorded; /* Number of rows in tables */
60 bool dirty; /* Flag for if a flush should occur */
61 bool crashed; /* Meta file is crashed */
63 ~Archive_share() override {
64 DBUG_PRINT("ha_archive", ("~Archive_share: %p", this));
69 }
72 }
76 int read_v1_metafile();
77};
78
79/*
80 Version for file format.
81 1 - Initial Version (Never Released)
82 2 - Stream Compression, separate blobs, no packing
83 3 - One steam (row and blobs), with packing
84*/
85#define ARCHIVE_VERSION 3
86
87class ha_archive : public handler {
88 THR_LOCK_DATA lock; /* MySQL lock */
89 Archive_share *share; /* Shared lock info */
90
91 azio_stream archive; /* Archive file we are working with */
92 my_off_t current_position; /* The position of the row we just read */
93 uchar byte_buffer[IO_SIZE]; /* Initial buffer for our string */
94 String buffer; /* Buffer used for blob storage */
95 ha_rows scan_rows; /* Number of rows left in scan */
96 bool bulk_insert; /* If we are performing a bulk insert */
102
105 unsigned int pack_row_v1(uchar *record);
106
107 public:
108 ha_archive(handlerton *hton, TABLE_SHARE *table_arg);
109 ~ha_archive() override = default;
110 const char *table_type() const override { return "ARCHIVE"; }
111 ulonglong table_flags() const override {
117 }
118 ulong index_flags(uint, uint, bool) const override {
119 return HA_ONLY_WHOLE_INDEX;
120 }
121 void get_auto_increment(ulonglong offset, ulonglong increment,
122 ulonglong nb_desired_values, ulonglong *first_value,
123 ulonglong *nb_reserved_values) override;
124 uint max_supported_keys() const override { return 1; }
125 uint max_supported_key_length() const override { return sizeof(ulonglong); }
127 [[maybe_unused]]) const override {
128 return sizeof(ulonglong);
129 }
130 int records(ha_rows *num_rows) override {
131 *num_rows = share->rows_recorded;
132 return 0;
133 }
134 int index_init(uint keynr, bool sorted) override;
135 int index_read(uchar *buf, const uchar *key, uint key_len,
136 enum ha_rkey_function find_flag) override;
137 virtual int index_read_idx(uchar *buf, uint index, const uchar *key,
138 uint key_len, enum ha_rkey_function find_flag);
139 int index_next(uchar *buf) override;
140 int open(const char *name, int mode, uint test_if_locked,
141 const dd::Table *table_def) override;
142 int close(void) override;
143 int write_row(uchar *buf) override;
144 int real_write_row(uchar *buf, azio_stream *writer);
145 int truncate(dd::Table *table_def) override;
146 int rnd_init(bool scan = true) override;
147 int rnd_next(uchar *buf) override;
148 int rnd_pos(uchar *buf, uchar *pos) override;
149 int get_row(azio_stream *file_to_read, uchar *buf);
150 int get_row_version2(azio_stream *file_to_read, uchar *buf);
151 int get_row_version3(azio_stream *file_to_read, uchar *buf);
152 Archive_share *get_share(const char *table_name, int *rc);
154 bool auto_repair() const override {
155 return true;
156 } // For the moment we just do this
157 int read_data_header(azio_stream *file_to_read);
158 void position(const uchar *record) override;
159 int info(uint) override;
160 int extra(enum ha_extra_function operation) override;
161 void update_create_info(HA_CREATE_INFO *create_info) override;
162 int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info,
163 dd::Table *table_def) override;
164 int optimize(THD *thd, HA_CHECK_OPT *check_opt) override;
165 int repair(THD *thd, HA_CHECK_OPT *check_opt) override;
166 void start_bulk_insert(ha_rows rows) override;
167 int end_bulk_insert() override;
168 enum row_type get_real_row_type(const HA_CREATE_INFO *) const override {
169 return ROW_TYPE_COMPRESSED;
170 }
172 enum thr_lock_type lock_type) override;
173 bool is_crashed() const override;
174 int check_for_upgrade(HA_CHECK_OPT *check_opt) override;
175 int check(THD *thd, HA_CHECK_OPT *check_opt) override;
176 bool check_and_repair(THD *thd) override;
178 bool fix_rec_buff(unsigned int length);
179 int unpack_row(azio_stream *file_to_read, uchar *record);
180 unsigned int pack_row(uchar *record, azio_stream *writer);
182 uint table_changes) override;
183};
Definition: ha_archive.h:50
Archive_share()
Definition: ha_archive.cc:247
ha_rows rows_recorded
Definition: ha_archive.h:55
bool crashed
Definition: ha_archive.h:61
azio_stream archive_write
Definition: ha_archive.h:54
~Archive_share() override
Definition: ha_archive.h:63
THR_LOCK lock
Definition: ha_archive.h:53
char table_name[FN_REFLEN]
Definition: ha_archive.h:56
int read_v1_metafile()
Read version 1 meta file (5.0 compatibility routine).
Definition: ha_archive.cc:286
int init_archive_writer()
Definition: ha_archive.cc:467
bool archive_write_open
Definition: ha_archive.h:59
bool dirty
Definition: ha_archive.h:60
void close_archive_writer()
Definition: ha_archive.cc:484
int write_v1_metafile()
Write version 1 meta file (5.0 compatibility routine).
Definition: ha_archive.cc:316
char data_file_name[FN_REFLEN]
Definition: ha_archive.h:57
bool in_optimize
Definition: ha_archive.h:58
mysql_mutex_t mutex
Definition: ha_archive.h:52
Base class to be used by handlers different shares.
Definition: handler.h:3956
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:168
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Definition: table.h:47
Definition: ha_archive.h:87
archive_record_buffer * record_buffer
Definition: ha_archive.h:100
ha_rows scan_rows
Definition: ha_archive.h:95
~ha_archive() override=default
int truncate(dd::Table *table_def) override
Quickly remove all rows from a table.
Definition: ha_archive.cc:1469
virtual int index_read_idx(uchar *buf, uint index, const uchar *key, uint key_len, enum ha_rkey_function find_flag)
Definition: ha_archive.cc:862
int check(THD *thd, HA_CHECK_OPT *check_opt) override
Definition: ha_archive.cc:1502
uint32 max_row_length(const uchar *buf)
Definition: ha_archive.cc:733
uint max_supported_key_length() const override
Definition: ha_archive.h:125
int close(void) override
Definition: ha_archive.cc:578
int write_row(uchar *buf) override
Write a row.
Definition: ha_archive.cc:784
THR_LOCK_DATA lock
Definition: ha_archive.h:88
bool bulk_insert
Definition: ha_archive.h:96
int real_write_row(uchar *buf, azio_stream *writer)
Definition: ha_archive.cc:708
bool auto_repair() const override
Check if the table can be automatically repaired.
Definition: ha_archive.h:154
int get_row_version3(azio_stream *file_to_read, uchar *buf)
Definition: ha_archive.cc:1031
archive_record_buffer * create_record_buffer(unsigned int length)
Definition: ha_archive.cc:1556
int rnd_pos(uchar *buf, uchar *pos) override
Definition: ha_archive.cc:1143
int extra(enum ha_extra_function operation) override
Handler hints.
Definition: ha_archive.cc:1414
my_off_t current_position
Definition: ha_archive.h:92
int info(uint) override
General method to gather info from handler.
Definition: ha_archive.cc:1348
ulong index_flags(uint, uint, bool) const override
Definition: ha_archive.h:118
void update_create_info(HA_CREATE_INFO *create_info) override
Update create info as part of ALTER TABLE.
Definition: ha_archive.cc:1332
int get_row_version2(azio_stream *file_to_read, uchar *buf)
Definition: ha_archive.cc:1039
int get_row(azio_stream *file_to_read, uchar *buf)
Definition: ha_archive.cc:939
bool archive_reader_open
Definition: ha_archive.h:101
Archive_share * get_share(const char *table_name, int *rc)
Definition: ha_archive.cc:415
int repair(THD *thd, HA_CHECK_OPT *check_opt) override
In this method check_opt can be modified to specify CHECK option to use to call check() upon the tabl...
Definition: ha_archive.cc:1162
int rnd_init(bool scan=true) override
rnd_init() can be called two times without rnd_end() in between (it only makes sense if scan=1).
Definition: ha_archive.cc:916
int rnd_next(uchar *buf) override
Definition: ha_archive.cc:1106
unsigned int pack_row(uchar *record, azio_stream *writer)
Definition: ha_archive.cc:747
bool fix_rec_buff(unsigned int length)
Definition: ha_archive.cc:955
uchar byte_buffer[IO_SIZE]
Definition: ha_archive.h:93
ulonglong table_flags() const override
Definition: ha_archive.h:111
void destroy_record_buffer(archive_record_buffer *r)
Definition: ha_archive.cc:1575
unsigned int pack_row_v1(uchar *record)
Pack version 1 row (5.0 compatibility routine).
Definition: ha_archive.cc:350
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info, dd::Table *table_def) override
Create table (implementation).
Definition: ha_archive.cc:600
int index_next(uchar *buf) override
Definition: ha_archive.cc:893
THR_LOCK_DATA ** store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type) override
Is not invoked for non-transactional temporary tables.
Definition: ha_archive.cc:1299
bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes) override
Part of old, deprecated in-place ALTER API.
Definition: ha_archive.cc:1581
int end_bulk_insert() override
Definition: ha_archive.cc:1455
int unpack_row(azio_stream *file_to_read, uchar *record)
Definition: ha_archive.cc:975
const char * table_type() const override
The following can be called without an open handler.
Definition: ha_archive.h:110
ha_archive(handlerton *hton, TABLE_SHARE *table_arg)
Definition: ha_archive.cc:261
int init_archive_reader()
Definition: ha_archive.cc:497
String buffer
Definition: ha_archive.h:94
bool check_and_repair(THD *thd) override
Check and repair the table if necessary.
Definition: ha_archive.cc:1549
void position(const uchar *record) override
Definition: ha_archive.cc:1131
int index_read(uchar *buf, const uchar *key, uint key_len, enum ha_rkey_function find_flag) override
Definition: ha_archive.cc:854
int open(const char *name, int mode, uint test_if_locked, const dd::Table *table_def) override
Definition: ha_archive.cc:523
int records(ha_rows *num_rows) override
Number of rows in table.
Definition: ha_archive.h:130
Archive_share * share
Definition: ha_archive.h:89
enum row_type get_real_row_type(const HA_CREATE_INFO *) const override
Get real row type for the table created based on one specified by user, CREATE TABLE options and SE c...
Definition: ha_archive.h:168
uint max_supported_keys() const override
Definition: ha_archive.h:124
uint current_k_offset
Definition: ha_archive.h:99
bool is_crashed() const override
Check if the table is crashed.
Definition: ha_archive.cc:1477
void start_bulk_insert(ha_rows rows) override
Definition: ha_archive.cc:1445
int read_data_header(azio_stream *file_to_read)
Definition: ha_archive.cc:372
uint max_supported_key_part_length(HA_CREATE_INFO *create_info) const override
Definition: ha_archive.h:126
uint current_key_len
Definition: ha_archive.h:98
azio_stream archive
Definition: ha_archive.h:91
int check_for_upgrade(HA_CHECK_OPT *check_opt) override
Check for upgrade.
Definition: ha_archive.cc:1491
int index_init(uint keynr, bool sorted) override
Definition: ha_archive.cc:844
void get_auto_increment(ulonglong offset, ulonglong increment, ulonglong nb_desired_values, ulonglong *first_value, ulonglong *nb_reserved_values) override
Reserves an interval of auto_increment values from the handler.
Definition: ha_archive.cc:836
int optimize(THD *thd, HA_CHECK_OPT *check_opt) override
Definition: ha_archive.cc:1176
const uchar * current_key
Definition: ha_archive.h:97
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4414
A table definition from the master.
Definition: rpl_utility.h:248
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:50
#define mysql_mutex_destroy(M)
Definition: mysql_mutex.h:46
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:57
ha_rkey_function
Definition: my_base.h:78
my_off_t ha_rows
Definition: my_base.h:1140
ha_extra_function
Definition: my_base.h:184
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:181
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
ulonglong my_off_t
Definition: my_inttypes.h:72
unsigned char uchar
Definition: my_inttypes.h:52
uint32_t uint32
Definition: my_inttypes.h:67
Common #defines and includes for file and socket I/O.
#define FN_REFLEN
Definition: my_io.h:83
constexpr const size_t IO_SIZE
Definition: my_io.h:159
static int record
Definition: mysqltest.cc:188
Definition: buf0block_hint.cc:30
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:79
const char * table_name
Definition: rules_table_service.cc:56
mode
Definition: file_handle.h:60
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86
required string key
Definition: replication_asynchronous_connection_failover.proto:60
#define HA_COUNT_ROWS_INSTANT
Definition: handler.h:332
#define HA_BINLOG_ROW_CAPABLE
Definition: handler.h:339
#define HA_CAN_BIT_FIELD
Definition: handler.h:329
#define HA_FILE_BASED
Definition: handler.h:324
#define HA_UPDATE_NOT_SUPPORTED
Handlers with this flag set do not support UPDATE operations.
Definition: handler.h:499
#define HA_DELETE_NOT_SUPPORTED
Handlers with this flag set do not support DELETE operations.
Definition: handler.h:504
#define HA_CAN_REPAIR
Definition: handler.h:369
#define HA_CAN_GEOMETRY
Definition: handler.h:228
row_type
Definition: handler.h:676
@ ROW_TYPE_COMPRESSED
Definition: handler.h:681
#define HA_BINLOG_STMT_CAPABLE
Definition: handler.h:340
#define HA_NO_TRANSACTIONS
Definition: handler.h:210
#define HA_STATS_RECORDS_IS_EXACT
Definition: handler.h:272
#define HA_ONLY_WHOLE_INDEX
Definition: handler.h:554
Our own string classes, used pervasively throughout the executor.
case opt name
Definition: sslopt-case.h:33
Definition: handler.h:3632
Struct to hold information about the table that should be created.
Definition: handler.h:3045
This structure is shared between different table objects.
Definition: table.h:690
Definition: table.h:1399
Definition: thr_lock.h:124
Definition: thr_lock.h:139
Definition: ha_archive.h:45
uint32 length
Definition: ha_archive.h:47
uchar * buffer
Definition: ha_archive.h:46
Definition: azlib.h:202
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2622
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
thr_lock_type
Definition: thr_lock.h:51
void thr_lock_delete(THR_LOCK *lock)
Definition: thr_lock.cc:322
unsigned int uint
Definition: uca9-dump.cc:75