Skip to content

Commit ab1a97f

Browse files
author
brian@zim.(none)
committed
Merge baker@bk-internal.mysql.com:/home/bk/mysql-5.1-arch
into zim.(none):/home/brian/mysql/archive-format-5.1
2 parents 05d05c7 + 9879f43 commit ab1a97f

File tree

9 files changed

+896
-496
lines changed

9 files changed

+896
-496
lines changed

mysql-test/r/archive.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
drop table if exists t1,t2,t3;
1+
drop table if exists t1,t2,t3,t4,t5;
22
CREATE TABLE t1 (
33
Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
44
Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL

mysql-test/t/archive.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-- source include/have_binlog_format_mixed_or_statement.inc
77

88
--disable_warnings
9-
drop table if exists t1,t2,t3;
9+
drop table if exists t1,t2,t3,t4,t5;
1010
--enable_warnings
1111

1212
CREATE TABLE t1 (

storage/archive/Makefile.am

+9-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LDADD =
3030
DEFS = @DEFS@
3131

3232
noinst_HEADERS = ha_archive.h azlib.h
33-
noinst_PROGRAMS = archive_test
33+
noinst_PROGRAMS = archive_test archive_reader
3434

3535
EXTRA_LTLIBRARIES = ha_archive.la
3636
pkglib_LTLIBRARIES = @plugin_archive_shared_target@
@@ -55,6 +55,14 @@ archive_test_LDADD = $(top_builddir)/mysys/libmysys.a \
5555
@ZLIB_LIBS@
5656
archive_test_LDFLAGS = @NOINST_LDFLAGS@
5757

58+
archive_reader_SOURCES = archive_reader.c azio.c
59+
archive_reader_CFLAGS = $(AM_CFLAGS)
60+
archive_reader_LDADD = $(top_builddir)/mysys/libmysys.a \
61+
$(top_builddir)/dbug/libdbug.a \
62+
$(top_builddir)/strings/libmystrings.a \
63+
@ZLIB_LIBS@
64+
archive_reader_LDFLAGS = @NOINST_LDFLAGS@
65+
5866

5967
EXTRA_DIST = CMakeLists.txt plug.in
6068
# Don't update the files from bitkeeper

storage/archive/archive_reader.c

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "azlib.h"
2+
#include <string.h>
3+
#include <assert.h>
4+
#include <stdio.h>
5+
6+
#define BUFFER_LEN 1024
7+
8+
int main(int argc, char *argv[])
9+
{
10+
unsigned int ret;
11+
azio_stream reader_handle;
12+
13+
MY_INIT(argv[0]);
14+
15+
if (argc < 2)
16+
{
17+
printf("No file specified. \n");
18+
return 0;
19+
}
20+
21+
if (!(ret= azopen(&reader_handle, argv[1], O_RDONLY|O_BINARY)))
22+
{
23+
printf("Could not create test file\n");
24+
return 0;
25+
}
26+
27+
printf("Version :%u\n", reader_handle.version);
28+
printf("Start position :%llu\n", (unsigned long long)reader_handle.start);
29+
printf("Block size :%u\n", reader_handle.block_size);
30+
printf("Rows: %llu\n", reader_handle.rows);
31+
printf("Autoincrement: %llu\n", reader_handle.auto_increment);
32+
printf("Check Point: %llu\n", reader_handle.check_point);
33+
printf("Forced Flushes: %llu\n", reader_handle.forced_flushes);
34+
printf("State: %s\n", ( reader_handle.dirty ? "dirty" : "clean"));
35+
36+
azclose(&reader_handle);
37+
38+
return 0;
39+
}

storage/archive/archive_test.c

+195-22
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,223 @@
1414
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
1515

1616
#include "azlib.h"
17+
#include <string.h>
18+
#include <assert.h>
1719
#include <stdio.h>
1820

19-
#define TEST_STRING "This is a test"
21+
#define TEST_FILENAME "test.az"
22+
#define TEST_STRING "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..."
23+
#define TEST_LOOP_NUM 100
2024
#define BUFFER_LEN 1024
25+
#define TWOGIG 2147483648
26+
#define FOURGIG 4294967296
27+
#define EIGHTGIG 8589934592
2128

22-
int main(int argc __attribute__((unused)), char *argv[])
29+
/* prototypes */
30+
int size_test(unsigned long long length, unsigned long long rows_to_test_for);
31+
32+
33+
int main(int argc, char *argv[])
2334
{
24-
int ret;
25-
azio_stream foo, foo1;
35+
unsigned int ret;
36+
37+
int error;
38+
unsigned int x;
39+
int written_rows= 0;
40+
azio_stream writer_handle, reader_handle;
2641
char buffer[BUFFER_LEN];
2742

43+
unlink(TEST_FILENAME);
44+
45+
if (argc > 1)
46+
return 0;
47+
2848
MY_INIT(argv[0]);
2949

30-
if (!(ret= azopen(&foo, "test", O_CREAT|O_WRONLY|O_TRUNC|O_BINARY)))
50+
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_BINARY)))
3151
{
3252
printf("Could not create test file\n");
3353
return 0;
3454
}
35-
azwrite(&foo, TEST_STRING, sizeof(TEST_STRING));
36-
azflush(&foo, Z_FINISH);
3755

38-
if (!(ret= azopen(&foo1, "test", O_RDONLY|O_BINARY)))
56+
if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY)))
57+
{
58+
printf("Could not open test file\n");
59+
return 0;
60+
}
61+
62+
assert(reader_handle.rows == 0);
63+
assert(reader_handle.auto_increment == 0);
64+
assert(reader_handle.check_point == 0);
65+
assert(reader_handle.forced_flushes == 0);
66+
assert(reader_handle.dirty == 1);
67+
68+
for (x= 0; x < TEST_LOOP_NUM; x++)
69+
{
70+
ret= azwrite(&writer_handle, TEST_STRING, BUFFER_LEN);
71+
assert(ret == BUFFER_LEN);
72+
written_rows++;
73+
}
74+
azflush(&writer_handle, Z_SYNC_FLUSH);
75+
76+
/* Lets test that our internal stats are good */
77+
assert(writer_handle.rows == TEST_LOOP_NUM);
78+
79+
/* Reader needs to be flushed to make sure it is up to date */
80+
azflush(&reader_handle, Z_SYNC_FLUSH);
81+
assert(reader_handle.rows == TEST_LOOP_NUM);
82+
assert(reader_handle.auto_increment == 0);
83+
assert(reader_handle.check_point == 0);
84+
assert(reader_handle.forced_flushes == 1);
85+
assert(reader_handle.dirty == 1);
86+
87+
writer_handle.auto_increment= 4;
88+
azflush(&writer_handle, Z_SYNC_FLUSH);
89+
assert(writer_handle.rows == TEST_LOOP_NUM);
90+
assert(writer_handle.auto_increment == 4);
91+
assert(writer_handle.check_point == 0);
92+
assert(writer_handle.forced_flushes == 2);
93+
assert(writer_handle.dirty == 1);
94+
95+
if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY)))
3996
{
4097
printf("Could not open test file\n");
4198
return 0;
4299
}
43-
ret= azread(&foo1, buffer, BUFFER_LEN);
44-
printf("Read %d bytes\n", ret);
45-
printf("%s\n", buffer);
46-
azrewind(&foo1);
47-
azclose(&foo);
48-
if (!(ret= azopen(&foo, "test", O_APPEND|O_WRONLY|O_BINARY)))
100+
101+
/* Read the original data */
102+
for (x= 0; x < writer_handle.rows; x++)
103+
{
104+
ret= azread(&reader_handle, buffer, BUFFER_LEN, &error);
105+
assert(!error);
106+
assert(ret == BUFFER_LEN);
107+
assert(!memcmp(buffer, TEST_STRING, ret));
108+
}
109+
assert(writer_handle.rows == TEST_LOOP_NUM);
110+
111+
/* Test here for falling off the planet */
112+
113+
/* Final Write before closing */
114+
ret= azwrite(&writer_handle, TEST_STRING, BUFFER_LEN);
115+
assert(ret == BUFFER_LEN);
116+
117+
/* We don't use FINISH, but I want to have it tested */
118+
azflush(&writer_handle, Z_FINISH);
119+
120+
assert(writer_handle.rows == TEST_LOOP_NUM+1);
121+
122+
/* Read final write */
123+
azrewind(&reader_handle);
124+
for (x= 0; x < writer_handle.rows; x++)
125+
{
126+
ret= azread(&reader_handle, buffer, BUFFER_LEN, &error);
127+
assert(ret == BUFFER_LEN);
128+
assert(!error);
129+
assert(!memcmp(buffer, TEST_STRING, ret));
130+
}
131+
132+
133+
azclose(&writer_handle);
134+
135+
/* Rewind and full test */
136+
azrewind(&reader_handle);
137+
for (x= 0; x < writer_handle.rows; x++)
138+
{
139+
ret= azread(&reader_handle, buffer, BUFFER_LEN, &error);
140+
assert(ret == BUFFER_LEN);
141+
assert(!error);
142+
assert(!memcmp(buffer, TEST_STRING, ret));
143+
}
144+
145+
printf("Finished reading\n");
146+
147+
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_RDWR|O_BINARY)))
148+
{
149+
printf("Could not open file (%s) for appending\n", TEST_FILENAME);
150+
return 0;
151+
}
152+
ret= azwrite(&writer_handle, TEST_STRING, BUFFER_LEN);
153+
assert(ret == BUFFER_LEN);
154+
azflush(&writer_handle, Z_SYNC_FLUSH);
155+
156+
/* Rewind and full test */
157+
azrewind(&reader_handle);
158+
for (x= 0; x < writer_handle.rows; x++)
159+
{
160+
ret= azread(&reader_handle, buffer, BUFFER_LEN, &error);
161+
assert(!error);
162+
assert(ret == BUFFER_LEN);
163+
assert(!memcmp(buffer, TEST_STRING, ret));
164+
}
165+
166+
azclose(&writer_handle);
167+
azclose(&reader_handle);
168+
unlink(TEST_FILENAME);
169+
170+
/* Start size tests */
171+
printf("About to run 2/4/8 gig tests now, you may want to hit CTRL-C\n");
172+
size_test(TWOGIG, 2097152);
173+
size_test(FOURGIG, 4194304);
174+
size_test(EIGHTGIG, 8388608);
175+
176+
return 0;
177+
}
178+
179+
int size_test(unsigned long long length, unsigned long long rows_to_test_for)
180+
{
181+
azio_stream writer_handle, reader_handle;
182+
unsigned long long write_length;
183+
unsigned long long read_length= 0;
184+
unsigned int ret;
185+
char buffer[BUFFER_LEN];
186+
int error;
187+
188+
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC|O_BINARY)))
49189
{
50190
printf("Could not create test file\n");
51191
return 0;
52192
}
53-
azwrite(&foo, TEST_STRING, sizeof(TEST_STRING));
54-
azflush(&foo, Z_FINISH);
55-
ret= azread(&foo1, buffer, BUFFER_LEN);
56-
printf("Read %d bytes\n", ret);
57-
printf("%s\n", buffer);
58-
azclose(&foo);
59-
azclose(&foo1);
60193

61-
/* unlink("test"); */
194+
for (write_length= 0; write_length < length ; write_length+= ret)
195+
{
196+
ret= azwrite(&writer_handle, TEST_STRING, BUFFER_LEN);
197+
if (ret != BUFFER_LEN)
198+
{
199+
printf("Size %u\n", ret);
200+
assert(ret != BUFFER_LEN);
201+
}
202+
if ((write_length % 14031) == 0)
203+
{
204+
azflush(&writer_handle, Z_SYNC_FLUSH);
205+
}
206+
}
207+
assert(write_length == length);
208+
azflush(&writer_handle, Z_SYNC_FLUSH);
209+
210+
printf("Reading back data\n");
211+
212+
if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY)))
213+
{
214+
printf("Could not open test file\n");
215+
return 0;
216+
}
217+
218+
while ((ret= azread(&reader_handle, buffer, BUFFER_LEN, &error)))
219+
{
220+
read_length+= ret;
221+
assert(!memcmp(buffer, TEST_STRING, ret));
222+
if (ret != BUFFER_LEN)
223+
{
224+
printf("Size %u\n", ret);
225+
assert(ret != BUFFER_LEN);
226+
}
227+
}
228+
229+
assert(read_length == length);
230+
assert(writer_handle.rows == rows_to_test_for);
231+
azclose(&writer_handle);
232+
azclose(&reader_handle);
233+
unlink(TEST_FILENAME);
234+
62235
return 0;
63236
}

0 commit comments

Comments
 (0)