MySQL 8.0.29
Source Code Documentation
ha_archive.h
Go to the documentation of this file.
1/* Copyright (c) 2003, 2021, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#include <sys/types.h>
24#include <zlib.h>
25
26#include "my_dbug.h"
27#include "my_inttypes.h"
28#include "my_io.h"
29#include "sql/handler.h"
30#include "sql_string.h"
32
33/**
34 @file storage/archive/ha_archive.h
35 Archive storage engine.
36*/
37
38/*
39 Please read ha_archive.cc first. If you are looking for more general
40 answers on how storage engines work, look at ha_example.cc and
41 ha_example.h.
42*/
43
47};
48
50 public:
53 azio_stream archive_write; /* Archive file we are working with */
54 ha_rows rows_recorded; /* Number of rows in tables */
59 bool dirty; /* Flag for if a flush should occur */
60 bool crashed; /* Meta file is crashed */
62 ~Archive_share() override {
63 DBUG_PRINT("ha_archive", ("~Archive_share: %p", this));
68 }
71 }
75 int read_v1_metafile();
76};
77
78/*
79 Version for file format.
80 1 - Initial Version (Never Released)
81 2 - Stream Compression, separate blobs, no packing
82 3 - One steam (row and blobs), with packing
83*/
84#define ARCHIVE_VERSION 3
85
86class ha_archive : public handler {
87 THR_LOCK_DATA lock; /* MySQL lock */
88 Archive_share *share; /* Shared lock info */
89
90 azio_stream archive; /* Archive file we are working with */
91 my_off_t current_position; /* The position of the row we just read */
92 uchar byte_buffer[IO_SIZE]; /* Initial buffer for our string */
93 String buffer; /* Buffer used for blob storage */
94 ha_rows scan_rows; /* Number of rows left in scan */
95 bool bulk_insert; /* If we are performing a bulk insert */
101
104 unsigned int pack_row_v1(uchar *record);
105
106 public:
107 ha_archive(handlerton *hton, TABLE_SHARE *table_arg);
108 ~ha_archive() override = default;
109 const char *table_type() const override { return "ARCHIVE"; }
110 ulonglong table_flags() const override {
116 }
117 ulong index_flags(uint, uint, bool) const override {
118 return HA_ONLY_WHOLE_INDEX;
119 }
120 void get_auto_increment(ulonglong offset, ulonglong increment,
121 ulonglong nb_desired_values, ulonglong *first_value,
122 ulonglong *nb_reserved_values) override;
123 uint max_supported_keys() const override { return 1; }
124 uint max_supported_key_length() const override { return sizeof(ulonglong); }
126 [[maybe_unused]]) const override {
127 return sizeof(ulonglong);
128 }
129 int records(ha_rows *num_rows) override {
130 *num_rows = share->rows_recorded;
131 return 0;
132 }
133 int index_init(uint keynr, bool sorted) override;
134 int index_read(uchar *buf, const uchar *key, uint key_len,
135 enum ha_rkey_function find_flag) override;
136 virtual int index_read_idx(uchar *buf, uint index, const uchar *key,
137 uint key_len, enum ha_rkey_function find_flag);
138 int index_next(uchar *buf) override;
139 int open(const char *name, int mode, uint test_if_locked,
140 const dd::Table *table_def) override;
141 int close(void) override;
142 int write_row(uchar *buf) override;
143 int real_write_row(uchar *buf, azio_stream *writer);
144 int truncate(dd::Table *table_def) override;
145 int rnd_init(bool scan = true) override;
146 int rnd_next(uchar *buf) override;
147 int rnd_pos(uchar *buf, uchar *pos) override;
148 int get_row(azio_stream *file_to_read, uchar *buf);
149 int get_row_version2(azio_stream *file_to_read, uchar *buf);
150 int get_row_version3(azio_stream *file_to_read, uchar *buf);
151 Archive_share *get_share(const char *table_name, int *rc);
153 bool auto_repair() const override {
154 return true;
155 } // For the moment we just do this
156 int read_data_header(azio_stream *file_to_read);
157 void position(const uchar *record) override;
158 int info(uint) override;
159 int extra(enum ha_extra_function operation) override;
160 void update_create_info(HA_CREATE_INFO *create_info) override;
161 int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info,
162 dd::Table *table_def) override;
163 int optimize(THD *thd, HA_CHECK_OPT *check_opt) override;
164 int repair(THD *thd, HA_CHECK_OPT *check_opt) override;
165 void start_bulk_insert(ha_rows rows) override;
166 int end_bulk_insert() override;
167 enum row_type get_real_row_type(const HA_CREATE_INFO *) const override {
168 return ROW_TYPE_COMPRESSED;
169 }
171 enum thr_lock_type lock_type) override;
172 bool is_crashed() const override;
173 int check_for_upgrade(HA_CHECK_OPT *check_opt) override;
174 int check(THD *thd, HA_CHECK_OPT *check_opt) override;
175 bool check_and_repair(THD *thd) override;
177 bool fix_rec_buff(unsigned int length);
178 int unpack_row(azio_stream *file_to_read, uchar *record);
179 unsigned int pack_row(uchar *record, azio_stream *writer);
181 uint table_changes) override;
182};
Definition: ha_archive.h:49
Archive_share()
Definition: ha_archive.cc:246
ha_rows rows_recorded
Definition: ha_archive.h:54
bool crashed
Definition: ha_archive.h:60
azio_stream archive_write
Definition: ha_archive.h:53
~Archive_share() override
Definition: ha_archive.h:62
THR_LOCK lock
Definition: ha_archive.h:52
char table_name[FN_REFLEN]
Definition: ha_archive.h:55
int read_v1_metafile()
Read version 1 meta file (5.0 compatibility routine).
Definition: ha_archive.cc:285
int init_archive_writer()
Definition: ha_archive.cc:466
bool archive_write_open
Definition: ha_archive.h:58
bool dirty
Definition: ha_archive.h:59
void close_archive_writer()
Definition: ha_archive.cc:483
int write_v1_metafile()
Write version 1 meta file (5.0 compatibility routine).
Definition: ha_archive.cc:315
char data_file_name[FN_REFLEN]
Definition: ha_archive.h:56
bool in_optimize
Definition: ha_archive.h:57
mysql_mutex_t mutex
Definition: ha_archive.h:51
Base class to be used by handlers different shares.
Definition: handler.h:3699
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:945
Definition: table.h:46
Definition: ha_archive.h:86
archive_record_buffer * record_buffer
Definition: ha_archive.h:99
ha_rows scan_rows
Definition: ha_archive.h:94
~ha_archive() override=default
int truncate(dd::Table *table_def) override
Quickly remove all rows from a table.
Definition: ha_archive.cc:1468
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:861
int check(THD *thd, HA_CHECK_OPT *check_opt) override
Definition: ha_archive.cc:1501
uint32 max_row_length(const uchar *buf)
Definition: ha_archive.cc:732
uint max_supported_key_length() const override
Definition: ha_archive.h:124
int close(void) override
Definition: ha_archive.cc:577
int write_row(uchar *buf) override
Write a row.
Definition: ha_archive.cc:783
THR_LOCK_DATA lock
Definition: ha_archive.h:87
bool bulk_insert
Definition: ha_archive.h:95
int real_write_row(uchar *buf, azio_stream *writer)
Definition: ha_archive.cc:707
bool auto_repair() const override
Check if the table can be automatically repaired.
Definition: ha_archive.h:153
int get_row_version3(azio_stream *file_to_read, uchar *buf)
Definition: ha_archive.cc:1030
archive_record_buffer * create_record_buffer(unsigned int length)
Definition: ha_archive.cc:1555
int rnd_pos(uchar *buf, uchar *pos) override
Definition: ha_archive.cc:1142
int extra(enum ha_extra_function operation) override
Handler hints.
Definition: ha_archive.cc:1413
my_off_t current_position
Definition: ha_archive.h:91
int info(uint) override
General method to gather info from handler.
Definition: ha_archive.cc:1347
ulong index_flags(uint, uint, bool) const override
Definition: ha_archive.h:117
void update_create_info(HA_CREATE_INFO *create_info) override
Update create info as part of ALTER TABLE.
Definition: ha_archive.cc:1331
int get_row_version2(azio_stream *file_to_read, uchar *buf)
Definition: ha_archive.cc:1038
int get_row(azio_stream *file_to_read, uchar *buf)
Definition: ha_archive.cc:938
bool archive_reader_open
Definition: ha_archive.h:100
Archive_share * get_share(const char *table_name, int *rc)
Definition: ha_archive.cc:414
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:1161
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:915
int rnd_next(uchar *buf) override
Definition: ha_archive.cc:1105
unsigned int pack_row(uchar *record, azio_stream *writer)
Definition: ha_archive.cc:746
bool fix_rec_buff(unsigned int length)
Definition: ha_archive.cc:954
uchar byte_buffer[IO_SIZE]
Definition: ha_archive.h:92
ulonglong table_flags() const override
Definition: ha_archive.h:110
void destroy_record_buffer(archive_record_buffer *r)
Definition: ha_archive.cc:1574
unsigned int pack_row_v1(uchar *record)
Pack version 1 row (5.0 compatibility routine).
Definition: ha_archive.cc:349
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info, dd::Table *table_def) override
Create table (implementation).
Definition: ha_archive.cc:599
int index_next(uchar *buf) override
Definition: ha_archive.cc:892
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:1298
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:1580
int end_bulk_insert() override
Definition: ha_archive.cc:1454
int unpack_row(azio_stream *file_to_read, uchar *record)
Definition: ha_archive.cc:974
const char * table_type() const override
The following can be called without an open handler.
Definition: ha_archive.h:109
ha_archive(handlerton *hton, TABLE_SHARE *table_arg)
Definition: ha_archive.cc:260
int init_archive_reader()
Definition: ha_archive.cc:496
String buffer
Definition: ha_archive.h:93
bool check_and_repair(THD *thd) override
Check and repair the table if necessary.
Definition: ha_archive.cc:1548
void position(const uchar *record) override
Definition: ha_archive.cc:1130
int index_read(uchar *buf, const uchar *key, uint key_len, enum ha_rkey_function find_flag) override
Definition: ha_archive.cc:853
int open(const char *name, int mode, uint test_if_locked, const dd::Table *table_def) override
Definition: ha_archive.cc:522
int records(ha_rows *num_rows) override
Number of rows in table.
Definition: ha_archive.h:129
Archive_share * share
Definition: ha_archive.h:88
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:167
uint max_supported_keys() const override
Definition: ha_archive.h:123
uint current_k_offset
Definition: ha_archive.h:98
bool is_crashed() const override
Check if the table is crashed.
Definition: ha_archive.cc:1476
void start_bulk_insert(ha_rows rows) override
Definition: ha_archive.cc:1444
int read_data_header(azio_stream *file_to_read)
Definition: ha_archive.cc:371
uint max_supported_key_part_length(HA_CREATE_INFO *create_info) const override
Definition: ha_archive.h:125
uint current_key_len
Definition: ha_archive.h:97
azio_stream archive
Definition: ha_archive.h:90
int check_for_upgrade(HA_CHECK_OPT *check_opt) override
Check for upgrade.
Definition: ha_archive.cc:1490
int index_init(uint keynr, bool sorted) override
Definition: ha_archive.cc:843
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:835
int optimize(THD *thd, HA_CHECK_OPT *check_opt) override
Definition: ha_archive.cc:1175
const uchar * current_key
Definition: ha_archive.h:96
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4157
A table definition from the master.
Definition: rpl_utility.h:247
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:49
#define mysql_mutex_destroy(M)
Definition: mysql_mutex.h:45
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:56
char * pos
Definition: do_ctype.cc:76
ha_rkey_function
Definition: my_base.h:77
my_off_t ha_rows
Definition: my_base.h:1139
ha_extra_function
Definition: my_base.h:183
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:180
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
ulonglong my_off_t
Definition: my_inttypes.h:71
unsigned char uchar
Definition: my_inttypes.h:51
uint32_t uint32
Definition: my_inttypes.h:66
Common #defines and includes for file and socket I/O.
#define FN_REFLEN
Definition: my_io.h:82
constexpr const size_t IO_SIZE
Definition: my_io.h:158
Definition: buf0block_hint.cc:29
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:75
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:78
const char * table_name
Definition: rules_table_service.cc:55
mode
Definition: file_handle.h:59
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:85
required string key
Definition: replication_asynchronous_connection_failover.proto:59
#define HA_COUNT_ROWS_INSTANT
Definition: handler.h:331
#define HA_BINLOG_ROW_CAPABLE
Definition: handler.h:338
#define HA_CAN_BIT_FIELD
Definition: handler.h:328
#define HA_FILE_BASED
Definition: handler.h:323
#define HA_UPDATE_NOT_SUPPORTED
Handlers with this flag set do not support UPDATE operations.
Definition: handler.h:498
#define HA_DELETE_NOT_SUPPORTED
Handlers with this flag set do not support DELETE operations.
Definition: handler.h:503
#define HA_CAN_REPAIR
Definition: handler.h:368
#define HA_CAN_GEOMETRY
Definition: handler.h:227
row_type
Definition: handler.h:675
@ ROW_TYPE_COMPRESSED
Definition: handler.h:680
#define HA_BINLOG_STMT_CAPABLE
Definition: handler.h:339
#define HA_NO_TRANSACTIONS
Definition: handler.h:209
#define HA_STATS_RECORDS_IS_EXACT
Definition: handler.h:271
#define HA_ONLY_WHOLE_INDEX
Definition: handler.h:553
Our own string classes, used pervasively throughout the executor.
case opt name
Definition: sslopt-case.h:32
Definition: handler.h:3375
Definition: handler.h:2790
This structure is shared between different table objects.
Definition: table.h:688
Definition: table.h:1394
Definition: thr_lock.h:123
Definition: thr_lock.h:138
Definition: ha_archive.h:44
uint32 length
Definition: ha_archive.h:46
uchar * buffer
Definition: ha_archive.h:45
Definition: azlib.h:202
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2416
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
Definition: mi_test3.cc:54
thr_lock_type
Definition: thr_lock.h:50
void thr_lock_delete(THR_LOCK *lock)
Definition: thr_lock.cc:321
unsigned int uint
Definition: uca-dump.cc:29