Skip to content

Commit 099c634

Browse files
author
brian@zim.(none)
committed
This patch passes comment to be embedded in ARZ.
Fixes autodiscovery of tables. Allows the FRM to be extracted from the ARZ file via archive_reader.
1 parent b2bfd35 commit 099c634

File tree

5 files changed

+278
-41
lines changed

5 files changed

+278
-41
lines changed

storage/archive/archive_reader.c

+50-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static const char *opt_tmpdir;
1818
static const char *new_auto_increment_value;
1919
static const char *load_default_groups[]= { "archive_reader", 0 };
2020
static char **default_argv;
21-
int opt_check, opt_force, opt_quiet, opt_backup= 0;
21+
int opt_check, opt_force, opt_quiet, opt_backup= 0, opt_extract_frm;
2222

2323
int main(int argc, char *argv[])
2424
{
@@ -53,6 +53,20 @@ int main(int argc, char *argv[])
5353
printf("\tLongest Row %u\n", reader_handle.longest_row);
5454
printf("\tShortest Row %u\n", reader_handle.shortest_row);
5555
printf("\tState %s\n", ( reader_handle.dirty ? "dirty" : "clean"));
56+
printf("\tFRM stored at %u\n", reader_handle.frm_start_pos);
57+
printf("\tComment stored at %u\n", reader_handle.comment_start_pos);
58+
printf("\tData starts at %u\n", (unsigned int)reader_handle.start);
59+
if (reader_handle.frm_start_pos)
60+
printf("\tFRM length %u\n", reader_handle.frm_length);
61+
if (reader_handle.comment_start_pos)
62+
{
63+
char *comment =
64+
(char *) malloc(sizeof(char) * reader_handle.comment_length);
65+
azread_comment(&reader_handle, comment);
66+
printf("\tComment length %u\n\t\t%.*s\n", reader_handle.comment_length,
67+
reader_handle.comment_length, comment);
68+
free(comment);
69+
}
5670
}
5771
else
5872
{
@@ -148,6 +162,23 @@ int main(int argc, char *argv[])
148162
}
149163

150164
writer_handle.auto_increment= reader_handle.auto_increment;
165+
if (reader_handle.frm_length)
166+
{
167+
char *ptr;
168+
ptr= (char *)my_malloc(sizeof(char) * reader_handle.frm_length, MYF(0));
169+
azread_frm(&reader_handle, ptr);
170+
azwrite_frm(&writer_handle, ptr, reader_handle.frm_length);
171+
my_free(ptr, MYF(0));
172+
}
173+
174+
if (reader_handle.comment_length)
175+
{
176+
char *ptr;
177+
ptr= (char *)my_malloc(sizeof(char) * reader_handle.comment_length, MYF(0));
178+
azread_comment(&reader_handle, ptr);
179+
azwrite_comment(&writer_handle, ptr, reader_handle.comment_length);
180+
my_free(ptr, MYF(0));
181+
}
151182

152183
while ((read= azread(&reader_handle, (byte *)size_buffer,
153184
ARCHIVE_ROW_HEADER_SIZE, &error)))
@@ -192,6 +223,18 @@ int main(int argc, char *argv[])
192223
azclose(&writer_handle);
193224
}
194225

226+
if (opt_extract_frm)
227+
{
228+
File frm_file;
229+
char *ptr;
230+
frm_file= my_open(argv[1], O_CREAT|O_RDWR|O_BINARY, MYF(0));
231+
ptr= (char *)my_malloc(sizeof(char) * reader_handle.frm_length, MYF(0));
232+
azread_frm(&reader_handle, ptr);
233+
my_write(frm_file, ptr, reader_handle.frm_length, MYF(0));
234+
my_close(frm_file, MYF(0));
235+
my_free(ptr, MYF(0));
236+
}
237+
195238
end:
196239
printf("\n");
197240
azclose(&reader_handle);
@@ -211,6 +254,9 @@ get_one_option(int optid,
211254
case 'c':
212255
opt_check= 1;
213256
break;
257+
case 'e':
258+
opt_extract_frm= 1;
259+
break;
214260
case 'f':
215261
opt_force= 1;
216262
printf("Not implemented yet\n");
@@ -257,6 +303,9 @@ static struct my_option my_long_options[] =
257303
"Output debug log. Often this is 'd:t:o,filename'.",
258304
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
259305
#endif
306+
{"extract-frm", 'e',
307+
"Extract the frm file.",
308+
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
260309
{"force", 'f',
261310
"Restart with -r if there are any errors in the table.",
262311
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},

storage/archive/archive_test.c

+25-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
#include <string.h>
1818
#include <assert.h>
1919
#include <stdio.h>
20+
#include <string.h>
2021
#include <my_getopt.h>
2122
#include <mysql_version.h>
2223

2324
#define ARCHIVE_ROW_HEADER_SIZE 4
2425

26+
#define COMMENT_STRING "Your bases"
27+
#define FRM_STRING "My bases"
2528
#define TEST_FILENAME "test.az"
2629
#define TEST_STRING_INIT "YOU don't know about me without you have read a book by the name of The Adventures of Tom Sawyer; but that ain't no matter. That book was made by Mr. Mark Twain, and he told the truth, mainly. There was things which he stretched, but mainly he told the truth. That is nothing. I never seen anybody but lied one time or another, without it was Aunt Polly, or the widow, or maybe Mary. Aunt Polly--Tom's Aunt Polly, she is--and Mary, and the Widow Douglas is all told about in that book, which is mostly a true book, with some stretchers, as I said before. Now the way that the book winds up is this: Tom and me found the money that the robbers hid in the cave, and it made us rich. We got six thousand dollars apiece--all gold. It was an awful sight of money when it was piled up. Well, Judge Thatcher he took it and put it out at interest, and it fetched us a dollar a day apiece all the year round --more than a body could tell what to do with. The Widow Douglas she took me for her son, and allowed she would..."
2730
#define TEST_LOOP_NUM 100
@@ -44,6 +47,7 @@ int size_test(unsigned long long length, unsigned long long rows_to_test_for);
4447
int main(int argc, char *argv[])
4548
{
4649
unsigned int ret;
50+
char comment_str[10];
4751

4852
int error;
4953
unsigned int x;
@@ -67,6 +71,19 @@ int main(int argc, char *argv[])
6771
return 0;
6872
}
6973

74+
azwrite_comment(&writer_handle, (char *)COMMENT_STRING,
75+
(unsigned int)strlen(COMMENT_STRING));
76+
azread_comment(&writer_handle, comment_str);
77+
assert(!memcmp(COMMENT_STRING, comment_str,
78+
strlen(COMMENT_STRING)));
79+
80+
azwrite_frm(&writer_handle, (char *)FRM_STRING,
81+
(unsigned int)strlen(FRM_STRING));
82+
azread_frm(&writer_handle, comment_str);
83+
assert(!memcmp(FRM_STRING, comment_str,
84+
strlen(FRM_STRING)));
85+
86+
7087
if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY)))
7188
{
7289
printf("Could not open test file\n");
@@ -87,22 +104,27 @@ int main(int argc, char *argv[])
87104
}
88105
azflush(&writer_handle, Z_SYNC_FLUSH);
89106

107+
azread_comment(&writer_handle, comment_str);
108+
assert(!memcmp(COMMENT_STRING, comment_str,
109+
strlen(COMMENT_STRING)));
110+
90111
/* Lets test that our internal stats are good */
91112
assert(writer_handle.rows == TEST_LOOP_NUM);
92113

93114
/* Reader needs to be flushed to make sure it is up to date */
94115
azflush(&reader_handle, Z_SYNC_FLUSH);
95116
assert(reader_handle.rows == TEST_LOOP_NUM);
96117
assert(reader_handle.auto_increment == 0);
97-
assert(reader_handle.check_point == 62);
118+
assert(reader_handle.check_point == 96);
98119
assert(reader_handle.forced_flushes == 1);
120+
assert(reader_handle.comment_length == 10);
99121
assert(reader_handle.dirty == AZ_STATE_SAVED);
100122

101123
writer_handle.auto_increment= 4;
102124
azflush(&writer_handle, Z_SYNC_FLUSH);
103125
assert(writer_handle.rows == TEST_LOOP_NUM);
104126
assert(writer_handle.auto_increment == 4);
105-
assert(writer_handle.check_point == 62);
127+
assert(writer_handle.check_point == 96);
106128
assert(writer_handle.forced_flushes == 2);
107129
assert(writer_handle.dirty == AZ_STATE_SAVED);
108130

@@ -181,7 +203,7 @@ int main(int argc, char *argv[])
181203
azflush(&reader_handle, Z_SYNC_FLUSH);
182204
assert(reader_handle.rows == 102);
183205
assert(reader_handle.auto_increment == 4);
184-
assert(reader_handle.check_point == 1256);
206+
assert(reader_handle.check_point == 1290);
185207
assert(reader_handle.forced_flushes == 4);
186208
assert(reader_handle.dirty == AZ_STATE_SAVED);
187209

storage/archive/azio.c

+81-4
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ int az_open (azio_stream *s, const char *path, int Flags, File fd)
128128
s->longest_row= 0;
129129
s->auto_increment= 0;
130130
s->check_point= 0;
131+
s->comment_start_pos= 0;
132+
s->comment_length= 0;
133+
s->frm_start_pos= 0;
134+
s->frm_length= 0;
131135
s->dirty= 1; /* We create the file dirty */
136+
s->start = AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
132137
write_header(s);
133138
my_seek(s->file, 0, MY_SEEK_END, MYF(0));
134139
}
@@ -153,7 +158,6 @@ void write_header(azio_stream *s)
153158
char buffer[AZHEADER_SIZE + AZMETA_BUFFER_SIZE];
154159
char *ptr= buffer;
155160

156-
s->start = AZHEADER_SIZE + AZMETA_BUFFER_SIZE;
157161
s->block_size= AZ_BUFSIZE;
158162
s->version = (unsigned char)az_magic[1];
159163
s->minor_version = (unsigned char)az_magic[2];
@@ -167,19 +171,25 @@ void write_header(azio_stream *s)
167171
*(ptr + AZ_BLOCK_POS)= (unsigned char)(s->block_size/1024); /* Reserved for block size */
168172
*(ptr + AZ_STRATEGY_POS)= (unsigned char)Z_DEFAULT_STRATEGY; /* Compression Type */
169173

170-
int4store(ptr + AZ_FRM_POS, 0); /* FRM Block */
174+
int4store(ptr + AZ_FRM_POS, s->frm_start_pos); /* FRM Block */
175+
int4store(ptr + AZ_FRM_LENGTH_POS, s->frm_length); /* FRM Block */
176+
int4store(ptr + AZ_COMMENT_POS, s->comment_start_pos); /* COMMENT Block */
177+
int4store(ptr + AZ_COMMENT_LENGTH_POS, s->comment_length); /* COMMENT Block */
171178
int4store(ptr + AZ_META_POS, 0); /* Meta Block */
179+
int4store(ptr + AZ_META_LENGTH_POS, 0); /* Meta Block */
172180
int8store(ptr + AZ_START_POS, (unsigned long long)s->start); /* Start of Data Block Index Block */
173181
int8store(ptr + AZ_ROW_POS, (unsigned long long)s->rows); /* Start of Data Block Index Block */
174182
int8store(ptr + AZ_FLUSH_POS, (unsigned long long)s->forced_flushes); /* Start of Data Block Index Block */
175183
int8store(ptr + AZ_CHECK_POS, (unsigned long long)s->check_point); /* Start of Data Block Index Block */
176184
int8store(ptr + AZ_AUTOINCREMENT_POS, (unsigned long long)s->auto_increment); /* Start of Data Block Index Block */
177185
int4store(ptr+ AZ_LONGEST_POS , s->longest_row); /* Longest row */
178186
int4store(ptr+ AZ_SHORTEST_POS, s->shortest_row); /* Shorest row */
187+
int4store(ptr+ AZ_FRM_POS,
188+
AZHEADER_SIZE + AZMETA_BUFFER_SIZE); /* FRM position */
179189
*(ptr + AZ_DIRTY_POS)= (unsigned char)s->dirty; /* Start of Data Block Index Block */
180190

181191
/* Always begin at the begining, and end there as well */
182-
my_pwrite(s->file, buffer, (uint)s->start, 0, MYF(0));
192+
my_pwrite(s->file, buffer, AZHEADER_SIZE + AZMETA_BUFFER_SIZE, 0, MYF(0));
183193
}
184194

185195
/* ===========================================================================
@@ -303,6 +313,8 @@ void check_header(azio_stream *s)
303313
buffer[len]= get_byte(s);
304314
s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
305315
read_header(s, buffer);
316+
for (; len < s->start; len++)
317+
get_byte(s);
306318
}
307319
else
308320
{
@@ -326,6 +338,10 @@ void read_header(azio_stream *s, unsigned char *buffer)
326338
s->auto_increment= (unsigned long long)uint8korr(buffer + AZ_AUTOINCREMENT_POS);
327339
s->longest_row= (unsigned int)uint4korr(buffer + AZ_LONGEST_POS);
328340
s->shortest_row= (unsigned int)uint4korr(buffer + AZ_SHORTEST_POS);
341+
s->frm_start_pos= (unsigned int)uint4korr(buffer + AZ_FRM_POS);
342+
s->frm_length= (unsigned int)uint4korr(buffer + AZ_FRM_LENGTH_POS);
343+
s->comment_start_pos= (unsigned int)uint4korr(buffer + AZ_COMMENT_POS);
344+
s->comment_length= (unsigned int)uint4korr(buffer + AZ_COMMENT_LENGTH_POS);
329345
s->dirty= (unsigned int)buffer[AZ_DIRTY_POS];
330346
}
331347
else
@@ -497,7 +513,6 @@ unsigned int azwrite (azio_stream *s, voidpc buf, unsigned int len)
497513
s->stream.next_in = (Bytef*)buf;
498514
s->stream.avail_in = len;
499515

500-
501516
s->rows++;
502517

503518
while (s->stream.avail_in != 0)
@@ -782,3 +797,65 @@ int azclose (azio_stream *s)
782797

783798
return destroy(s);
784799
}
800+
801+
/*
802+
Though this was added to support MySQL's FRM file, anything can be
803+
stored in this location.
804+
*/
805+
int azwrite_frm(azio_stream *s, char *blob, unsigned int length)
806+
{
807+
if (s->mode == 'r')
808+
return 1;
809+
810+
if (s->rows > 0)
811+
return 1;
812+
813+
s->frm_start_pos= s->start;
814+
s->frm_length= length;
815+
s->start+= length;
816+
817+
my_pwrite(s->file, blob, s->frm_length, s->frm_start_pos, MYF(0));
818+
819+
write_header(s);
820+
my_seek(s->file, 0, MY_SEEK_END, MYF(0));
821+
822+
return 0;
823+
}
824+
825+
int azread_frm(azio_stream *s, char *blob)
826+
{
827+
my_pread(s->file, blob, s->frm_length, s->frm_start_pos, MYF(0));
828+
829+
return 0;
830+
}
831+
832+
833+
/*
834+
Simple comment field
835+
*/
836+
int azwrite_comment(azio_stream *s, char *blob, unsigned int length)
837+
{
838+
if (s->mode == 'r')
839+
return 1;
840+
841+
if (s->rows > 0)
842+
return 1;
843+
844+
s->comment_start_pos= s->start;
845+
s->comment_length= length;
846+
s->start+= length;
847+
848+
my_pwrite(s->file, blob, s->comment_length, s->comment_start_pos, MYF(0));
849+
850+
write_header(s);
851+
my_seek(s->file, 0, MY_SEEK_END, MYF(0));
852+
853+
return 0;
854+
}
855+
856+
int azread_comment(azio_stream *s, char *blob)
857+
{
858+
my_pread(s->file, blob, s->comment_length, s->comment_start_pos, MYF(0));
859+
860+
return 0;
861+
}

storage/archive/azlib.h

+24-10
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,30 @@ extern "C" {
4949
#define AZMETA_BUFFER_SIZE sizeof(unsigned long long) \
5050
+ sizeof(unsigned long long) + sizeof(unsigned long long) + sizeof(unsigned long long) \
5151
+ sizeof(unsigned int) + sizeof(unsigned int) \
52+
+ sizeof(unsigned int) + sizeof(unsigned int) \
5253
+ sizeof(unsigned char)
5354

54-
#define AZHEADER_SIZE 21
55+
#define AZHEADER_SIZE 29
5556

5657
#define AZ_MAGIC_POS 0
5758
#define AZ_VERSION_POS 1
5859
#define AZ_MINOR_VERSION_POS 2
5960
#define AZ_BLOCK_POS 3
6061
#define AZ_STRATEGY_POS 4
6162
#define AZ_FRM_POS 5
62-
#define AZ_META_POS 9
63-
#define AZ_START_POS 13
64-
#define AZ_ROW_POS 21
65-
#define AZ_FLUSH_POS 29
66-
#define AZ_CHECK_POS 37
67-
#define AZ_AUTOINCREMENT_POS 45
68-
#define AZ_LONGEST_POS 53
69-
#define AZ_SHORTEST_POS 57
70-
#define AZ_DIRTY_POS 61
63+
#define AZ_FRM_LENGTH_POS 9
64+
#define AZ_META_POS 13
65+
#define AZ_META_LENGTH_POS 17
66+
#define AZ_START_POS 21
67+
#define AZ_ROW_POS 29
68+
#define AZ_FLUSH_POS 37
69+
#define AZ_CHECK_POS 45
70+
#define AZ_AUTOINCREMENT_POS 53
71+
#define AZ_LONGEST_POS 61
72+
#define AZ_SHORTEST_POS 65
73+
#define AZ_COMMENT_POS 69
74+
#define AZ_COMMENT_LENGTH_POS 73
75+
#define AZ_DIRTY_POS 77
7176

7277

7378
/*
@@ -220,6 +225,10 @@ typedef struct azio_stream {
220225
unsigned int longest_row; /* Longest row */
221226
unsigned int shortest_row; /* Shortest row */
222227
unsigned char dirty; /* State of file */
228+
unsigned int frm_start_pos; /* Position for start of FRM */
229+
unsigned int frm_length; /* Position for start of FRM */
230+
unsigned int comment_start_pos; /* Position for start of comment */
231+
unsigned int comment_length; /* Position for start of comment */
223232
} azio_stream;
224233

225234
/* basic functions */
@@ -322,6 +331,11 @@ extern int azclose(azio_stream *file);
322331
error number (see function gzerror below).
323332
*/
324333

334+
extern int azwrite_frm (azio_stream *s, char *blob, unsigned int length);
335+
extern int azread_frm (azio_stream *s, char *blob);
336+
extern int azwrite_comment (azio_stream *s, char *blob, unsigned int length);
337+
extern int azread_comment (azio_stream *s, char *blob);
338+
325339
#ifdef __cplusplus
326340
}
327341
#endif

0 commit comments

Comments
 (0)