Commit 2b3f5085 authored by unknown's avatar unknown

New azio which keeps meta data in its own header.


storage/archive/Makefile.am:
  Added archive reader
storage/archive/archive_test.c:
  Extended archive test
storage/archive/azio.c:
  Rewrite of azio to include support for more meta data in header
storage/archive/azlib.h:
  Extended information.
storage/archive/ha_archive.cc:
  Rewrite to handle new azio
storage/archive/ha_archive.h:
  Rewrite to handle new azio.
storage/archive/archive_reader.c:
  New BitKeeper file ``storage/archive/archive_reader.c''
parent f8d93bb3
...@@ -31,7 +31,7 @@ LDADD = ...@@ -31,7 +31,7 @@ LDADD =
DEFS = @DEFS@ DEFS = @DEFS@
noinst_HEADERS = ha_archive.h azlib.h noinst_HEADERS = ha_archive.h azlib.h
noinst_PROGRAMS = archive_test noinst_PROGRAMS = archive_test archive_reader
EXTRA_LTLIBRARIES = ha_archive.la EXTRA_LTLIBRARIES = ha_archive.la
pkglib_LTLIBRARIES = @plugin_archive_shared_target@ pkglib_LTLIBRARIES = @plugin_archive_shared_target@
...@@ -56,6 +56,14 @@ archive_test_LDADD = $(top_builddir)/mysys/libmysys.a \ ...@@ -56,6 +56,14 @@ archive_test_LDADD = $(top_builddir)/mysys/libmysys.a \
@ZLIB_LIBS@ @ZLIB_LIBS@
archive_test_LDFLAGS = @NOINST_LDFLAGS@ archive_test_LDFLAGS = @NOINST_LDFLAGS@
archive_reader_SOURCES = archive_reader.c azio.c
archive_reader_CFLAGS = $(AM_CFLAGS)
archive_reader_LDADD = $(top_builddir)/mysys/libmysys.a \
$(top_builddir)/dbug/libdbug.a \
$(top_builddir)/strings/libmystrings.a \
@ZLIB_LIBS@
archive_reader_LDFLAGS = @NOINST_LDFLAGS@
EXTRA_DIST = CMakeLists.txt plug.in EXTRA_DIST = CMakeLists.txt plug.in
# Don't update the files from bitkeeper # Don't update the files from bitkeeper
......
#include "azlib.h"
#include <string.h>
#include <assert.h>
#include <stdio.h>
#define BUFFER_LEN 1024
int main(int argc, char *argv[])
{
unsigned int ret;
azio_stream reader_handle;
MY_INIT(argv[0]);
if (argc < 2)
{
printf("No file specified. \n");
return 0;
}
if (!(ret= azopen(&reader_handle, argv[1], O_RDONLY|O_BINARY)))
{
printf("Could not create test file\n");
return 0;
}
printf("Version :%u\n", reader_handle.version);
printf("Start position :%llu\n", (unsigned long long)reader_handle.start);
printf("Block size :%u\n", reader_handle.block_size);
printf("Rows: %llu\n", reader_handle.rows);
printf("Autoincrement: %llu\n", reader_handle.auto_increment);
printf("Check Point: %llu\n", reader_handle.check_point);
printf("Forced Flushes: %llu\n", reader_handle.forced_flushes);
printf("State: %s\n", ( reader_handle.dirty ? "dirty" : "clean"));
azclose(&reader_handle);
return 0;
}
...@@ -5,88 +5,192 @@ ...@@ -5,88 +5,192 @@
#define TEST_FILENAME "test.az" #define TEST_FILENAME "test.az"
#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..." #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..."
#define TEST_LOOP_NUM 100
#define BUFFER_LEN 1024 #define BUFFER_LEN 1024
#define TWOGIG 2147483648 #define TWOGIG 2147483648
#define FOURGIG 4294967296 #define FOURGIG 4294967296
#define EIGHTGIG 8589934592
int main(int argc __attribute__((unused)), char *argv[]) /* prototypes */
int size_test(unsigned long long length, unsigned long long rows_to_test_for);
int main(int argc, char *argv[])
{ {
unsigned long ret; unsigned int ret;
int error; int error;
unsigned int x;
int written_rows= 0;
azio_stream writer_handle, reader_handle; azio_stream writer_handle, reader_handle;
char buffer[BUFFER_LEN]; char buffer[BUFFER_LEN];
unsigned long write_length;
unsigned long read_length= 0; unlink(TEST_FILENAME);
if (argc > 1)
return 0;
MY_INIT(argv[0]); MY_INIT(argv[0]);
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY))) if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_BINARY)))
{ {
printf("Could not create test file\n"); printf("Could not create test file\n");
return 0; return 0;
} }
ret= azwrite(&writer_handle, TEST_STRING, BUFFER_LEN);
assert(ret == BUFFER_LEN);
azflush(&writer_handle, Z_FINISH);
if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY))) if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY)))
{ {
printf("Could not open test file\n"); printf("Could not open test file\n");
return 0; return 0;
} }
ret= azread(&reader_handle, buffer, BUFFER_LEN, &error);
printf("Read %lu bytes, expected %d\n", ret, BUFFER_LEN);
assert(reader_handle.rows == 0);
assert(reader_handle.auto_increment == 0);
assert(reader_handle.check_point == 0);
assert(reader_handle.forced_flushes == 0);
assert(reader_handle.dirty == 1);
for (x= 0; x < TEST_LOOP_NUM; x++)
{
ret= azwrite(&writer_handle, TEST_STRING, BUFFER_LEN);
assert(ret == BUFFER_LEN);
written_rows++;
}
azflush(&writer_handle, Z_SYNC_FLUSH);
/* Lets test that our internal stats are good */
assert(writer_handle.rows == TEST_LOOP_NUM);
/* Reader needs to be flushed to make sure it is up to date */
azflush(&reader_handle, Z_SYNC_FLUSH);
assert(reader_handle.rows == TEST_LOOP_NUM);
assert(reader_handle.auto_increment == 0);
assert(reader_handle.check_point == 0);
assert(reader_handle.forced_flushes == 1);
assert(reader_handle.dirty == 1);
writer_handle.auto_increment= 4;
azflush(&writer_handle, Z_SYNC_FLUSH);
assert(writer_handle.rows == TEST_LOOP_NUM);
assert(writer_handle.auto_increment == 4);
assert(writer_handle.check_point == 0);
assert(writer_handle.forced_flushes == 2);
assert(writer_handle.dirty == 1);
if (!(ret= azopen(&reader_handle, TEST_FILENAME, O_RDONLY|O_BINARY)))
{
printf("Could not open test file\n");
return 0;
}
/* Read the original data */
for (x= 0; x < writer_handle.rows; x++)
{
ret= azread(&reader_handle, buffer, BUFFER_LEN, &error);
assert(!error);
assert(ret == BUFFER_LEN);
assert(!memcmp(buffer, TEST_STRING, ret));
}
assert(writer_handle.rows == TEST_LOOP_NUM);
/* Test here for falling off the planet */
/* Final Write before closing */
ret= azwrite(&writer_handle, TEST_STRING, BUFFER_LEN);
assert(ret == BUFFER_LEN);
/* We don't use FINISH, but I want to have it tested */
azflush(&writer_handle, Z_FINISH);
assert(writer_handle.rows == TEST_LOOP_NUM+1);
/* Read final write */
azrewind(&reader_handle); azrewind(&reader_handle);
for (x= 0; x < writer_handle.rows; x++)
{
ret= azread(&reader_handle, buffer, BUFFER_LEN, &error);
assert(ret == BUFFER_LEN);
assert(!error);
assert(!memcmp(buffer, TEST_STRING, ret));
}
azclose(&writer_handle); azclose(&writer_handle);
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_APPEND|O_WRONLY|O_BINARY))) /* Rewind and full test */
azrewind(&reader_handle);
for (x= 0; x < writer_handle.rows; x++)
{
ret= azread(&reader_handle, buffer, BUFFER_LEN, &error);
assert(ret == BUFFER_LEN);
assert(!error);
assert(!memcmp(buffer, TEST_STRING, ret));
}
printf("Finished reading\n");
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_RDWR|O_BINARY)))
{ {
printf("Could not open file (%s) for appending\n", TEST_FILENAME); printf("Could not open file (%s) for appending\n", TEST_FILENAME);
return 0; return 0;
} }
ret= azwrite(&writer_handle, TEST_STRING, BUFFER_LEN); ret= azwrite(&writer_handle, TEST_STRING, BUFFER_LEN);
assert(ret == BUFFER_LEN); assert(ret == BUFFER_LEN);
azflush(&writer_handle, Z_FINISH); azflush(&writer_handle, Z_SYNC_FLUSH);
/* Read the original data */ /* Rewind and full test */
ret= azread(&reader_handle, buffer, BUFFER_LEN, &error); azrewind(&reader_handle);
printf("Read %lu bytes, expected %d\n", ret, BUFFER_LEN); for (x= 0; x < writer_handle.rows; x++)
assert(ret == BUFFER_LEN); {
assert(!error); ret= azread(&reader_handle, buffer, BUFFER_LEN, &error);
assert(!error);
/* Read the new data */ assert(ret == BUFFER_LEN);
ret= azread(&reader_handle, buffer, BUFFER_LEN, &error); assert(!memcmp(buffer, TEST_STRING, ret));
printf("Read %lu bytes, expected %d\n", ret, BUFFER_LEN); }
assert(ret == BUFFER_LEN);
assert(!error);
azclose(&writer_handle); azclose(&writer_handle);
azclose(&reader_handle); azclose(&reader_handle);
unlink(TEST_FILENAME); unlink(TEST_FILENAME);
/* Start size tests */ /* Start size tests */
printf("About to run 2gig and 4gig test now, you may want to hit CTRL-C\n"); printf("About to run 2/4/8 gig tests now, you may want to hit CTRL-C\n");
size_test(TWOGIG, 2097152);
size_test(FOURGIG, 4194304);
size_test(EIGHTGIG, 8388608);
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY))) return 0;
}
int size_test(unsigned long long length, unsigned long long rows_to_test_for)
{
azio_stream writer_handle, reader_handle;
unsigned long long write_length;
unsigned long long read_length= 0;
unsigned int ret;
char buffer[BUFFER_LEN];
int error;
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_RDWR|O_TRUNC|O_BINARY)))
{ {
printf("Could not create test file\n"); printf("Could not create test file\n");
return 0; return 0;
} }
for (write_length= 0; write_length < TWOGIG ; write_length+= ret) for (write_length= 0; write_length < length ; write_length+= ret)
{ {
ret= azwrite(&writer_handle, TEST_STRING, BUFFER_LEN); ret= azwrite(&writer_handle, TEST_STRING, BUFFER_LEN);
assert(!error);
if (ret != BUFFER_LEN) if (ret != BUFFER_LEN)
{ {
printf("Size %lu\n", ret); printf("Size %u\n", ret);
assert(ret != BUFFER_LEN); assert(ret != BUFFER_LEN);
} }
if ((write_length % 14031) == 0)
{
azflush(&writer_handle, Z_SYNC_FLUSH);
}
} }
assert(write_length == TWOGIG); assert(write_length == length);
printf("Read %lu bytes, expected %lu\n", write_length, TWOGIG); azflush(&writer_handle, Z_SYNC_FLUSH);
azflush(&writer_handle, Z_FINISH);
printf("Reading back data\n"); printf("Reading back data\n");
...@@ -102,29 +206,13 @@ int main(int argc __attribute__((unused)), char *argv[]) ...@@ -102,29 +206,13 @@ int main(int argc __attribute__((unused)), char *argv[])
assert(!memcmp(buffer, TEST_STRING, ret)); assert(!memcmp(buffer, TEST_STRING, ret));
if (ret != BUFFER_LEN) if (ret != BUFFER_LEN)
{ {
printf("Size %lu\n", ret); printf("Size %u\n", ret);
assert(ret != BUFFER_LEN); assert(ret != BUFFER_LEN);
} }
} }
assert(read_length == TWOGIG); assert(read_length == length);
azclose(&writer_handle); assert(writer_handle.rows == rows_to_test_for);
azclose(&reader_handle);
unlink(TEST_FILENAME);
if (!(ret= azopen(&writer_handle, TEST_FILENAME, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY)))
{
printf("Could not create test file\n");
return 0;
}
for (write_length= 0; write_length < FOURGIG ; write_length+= ret)
{
ret= azwrite(&writer_handle, TEST_STRING, BUFFER_LEN);
assert(ret == BUFFER_LEN);
}
assert(write_length == FOURGIG);
printf("Read %lu bytes, expected %lu\n", write_length, FOURGIG);
azclose(&writer_handle); azclose(&writer_handle);
azclose(&reader_handle); azclose(&reader_handle);
unlink(TEST_FILENAME); unlink(TEST_FILENAME);
......
This diff is collapsed.
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <zlib.h> #include <zlib.h>
#include "../../mysys/mysys_priv.h" #include "../../mysys/mysys_priv.h"
#include <my_dir.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -45,11 +46,24 @@ extern "C" { ...@@ -45,11 +46,24 @@ extern "C" {
/* /*
ulonglong + ulonglong + ulonglong + ulonglong + uchar ulonglong + ulonglong + ulonglong + ulonglong + uchar
*/ */
#define AZMETA_BUFFER_SIZE sizeof(ulonglong) \ #define AZMETA_BUFFER_SIZE sizeof(unsigned long long) \
+ sizeof(ulonglong) + sizeof(ulonglong) + sizeof(ulonglong) \ + sizeof(unsigned long long) + sizeof(unsigned long long) + sizeof(unsigned long long) \
+ sizeof(uchar) + sizeof(unsigned char)
#define AZHEADER_SIZE 16 #define AZHEADER_SIZE 20
#define AZ_MAGIC_POS 0
#define AZ_VERSION_POS 1
#define AZ_BLOCK_POS 2
#define AZ_STRATEGY_POS 3
#define AZ_FRM_POS 4
#define AZ_META_POS 8
#define AZ_START_POS 12
#define AZ_ROW_POS 20
#define AZ_FLUSH_POS 28
#define AZ_CHECK_POS 36
#define AZ_AUTOINCREMENT_POS 44
#define AZ_DIRTY_POS 52
/* /*
The 'zlib' compression library provides in-memory compression and The 'zlib' compression library provides in-memory compression and
...@@ -164,7 +178,7 @@ extern "C" { ...@@ -164,7 +178,7 @@ extern "C" {
/* The deflate compression method (the only one supported in this version) */ /* The deflate compression method (the only one supported in this version) */
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
#define Z_BUFSIZE 16384 #define AZ_BUFSIZE 16384
typedef struct azio_stream { typedef struct azio_stream {
...@@ -172,8 +186,8 @@ typedef struct azio_stream { ...@@ -172,8 +186,8 @@ typedef struct azio_stream {
int z_err; /* error code for last stream operation */ int z_err; /* error code for last stream operation */
int z_eof; /* set if end of input file */ int z_eof; /* set if end of input file */
File file; /* .gz file */ File file; /* .gz file */
Byte inbuf[Z_BUFSIZE]; /* input buffer */ Byte inbuf[AZ_BUFSIZE]; /* input buffer */
Byte outbuf[Z_BUFSIZE]; /* output buffer */ Byte outbuf[AZ_BUFSIZE]; /* output buffer */
uLong crc; /* crc32 of uncompressed data */ uLong crc; /* crc32 of uncompressed data */
char *msg; /* error message */ char *msg; /* error message */
int transparent; /* 1 if input file is not a .gz file */ int transparent; /* 1 if input file is not a .gz file */
...@@ -184,6 +198,12 @@ typedef struct azio_stream { ...@@ -184,6 +198,12 @@ typedef struct azio_stream {
int back; /* one character push-back */ int back; /* one character push-back */
int last; /* true if push-back is last character */ int last; /* true if push-back is last character */
unsigned char version; /* Version */ unsigned char version; /* Version */
unsigned int block_size; /* Block Size */
unsigned long long check_point; /* Last position we checked */
unsigned long long forced_flushes; /* Forced Flushes */
unsigned long long rows; /* rows */
unsigned long long auto_increment; /* auto increment field */
unsigned char dirty; /* State of file */
} azio_stream; } azio_stream;
/* basic functions */ /* basic functions */
...@@ -219,7 +239,7 @@ int azdopen(azio_stream *s,File fd, int Flags); ...@@ -219,7 +239,7 @@ int azdopen(azio_stream *s,File fd, int Flags);
*/ */
extern unsigned long azread ( azio_stream *s, voidp buf, unsigned long len, int *error); extern unsigned int azread ( azio_stream *s, voidp buf, unsigned int len, int *error);
/* /*
Reads the given number of uncompressed bytes from the compressed file. Reads the given number of uncompressed bytes from the compressed file.
If the input file was not in gzip format, gzread copies the given number If the input file was not in gzip format, gzread copies the given number
...@@ -227,10 +247,10 @@ extern unsigned long azread ( azio_stream *s, voidp buf, unsigned long len, int ...@@ -227,10 +247,10 @@ extern unsigned long azread ( azio_stream *s, voidp buf, unsigned long len, int
gzread returns the number of uncompressed bytes actually read (0 for gzread returns the number of uncompressed bytes actually read (0 for
end of file, -1 for error). */ end of file, -1 for error). */
extern unsigned long azwrite (azio_stream *s, voidpc buf, unsigned long len); extern unsigned int azwrite (azio_stream *s, voidpc buf, unsigned int len);
/* /*
Writes the given number of uncompressed bytes into the compressed file. Writes the given number of uncompressed bytes into the compressed file.
gzwrite returns the number of uncompressed bytes actually written azwrite returns the number of uncompressed bytes actually written
(0 in case of error). (0 in case of error).
*/ */
......
This diff is collapsed.
...@@ -39,17 +39,12 @@ typedef struct st_archive_share { ...@@ -39,17 +39,12 @@ typedef struct st_archive_share {
uint table_name_length,use_count; uint table_name_length,use_count;
pthread_mutex_t mutex; pthread_mutex_t mutex;
THR_LOCK lock; THR_LOCK lock;
File meta_file; /* Meta file we use */
azio_stream archive_write; /* Archive file we are working with */ azio_stream archive_write; /* Archive file we are working with */
bool archive_write_open; bool archive_write_open;
bool dirty; /* Flag for if a flush should occur */ bool dirty; /* Flag for if a flush should occur */
bool crashed; /* Meta file is crashed */ bool crashed; /* Meta file is crashed */
ha_rows rows_recorded; /* Number of rows in tables */ ha_rows rows_recorded; /* Number of rows in tables */
ulonglong auto_increment_value;
ulonglong forced_flushes;
ulonglong mean_rec_length; ulonglong mean_rec_length;
char real_path[FN_REFLEN];
uint meta_version;
} ARCHIVE_SHARE; } ARCHIVE_SHARE;
/* /*
...@@ -121,16 +116,6 @@ public: ...@@ -121,16 +116,6 @@ public:
int get_row(azio_stream *file_to_read, byte *buf); int get_row(azio_stream *file_to_read, byte *buf);
int get_row_version2(azio_stream *file_to_read, byte *buf); int get_row_version2(azio_stream *file_to_read, byte *buf);
int get_row_version3(azio_stream *file_to_read, byte *buf); int get_row_version3(azio_stream *file_to_read, byte *buf);
int read_meta_file(File meta_file, ha_rows *rows,
uint *meta_version,
ulonglong *auto_increment,
ulonglong *forced_flushes,
char *real_path);
int write_meta_file(File meta_file, ha_rows rows,
ulonglong auto_increment,
ulonglong forced_flushes,
char *real_path,
bool dirty);
ARCHIVE_SHARE *get_share(const char *table_name, TABLE *table, int *rc); ARCHIVE_SHARE *get_share(const char *table_name, TABLE *table, int *rc);
int free_share(ARCHIVE_SHARE *share); int free_share(ARCHIVE_SHARE *share);
int init_archive_writer(); int init_archive_writer();
...@@ -156,6 +141,6 @@ public: ...@@ -156,6 +141,6 @@ public:
int max_row_length(const byte *buf); int max_row_length(const byte *buf);
bool fix_rec_buff(int length); bool fix_rec_buff(int length);
int unpack_row(azio_stream *file_to_read, char *record); int unpack_row(azio_stream *file_to_read, char *record);
unsigned long pack_row(const byte *record); unsigned int pack_row(const byte *record);
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment