summaryrefslogtreecommitdiffstats
path: root/xlators/features
diff options
context:
space:
mode:
authorJoseph Fernandes <josferna@redhat.com>2015-10-14 00:00:41 +0530
committerDan Lambright <dlambrig@redhat.com>2015-11-08 05:22:02 -0800
commit5c0e815f69a0fb1f9c3f9b5555642dcb2295f209 (patch)
tree621fde60b15813fc7529344004ed9a0891ffae4a /xlators/features
parentf0193ce9b6b76647483f1380e7a8d791a5e64e61 (diff)
tier/libgfdb: Replacing ASCII query file with binary
Earlier, when the database was queried we used to save all the queried records in an ASCII format in the query file. This caused issues like filename having ASCII delimiter and used to take a lot of space. The tier.c file also had a lot of parsing code. Here we changed the format of the query file to binary. All the logic of serialization and formating of query record is done by libgfdb. Libgfdb provides API, gfdb_write_query_record() and gfdb_read_query_record(), which the user i.e tier migrator and CTR xlator can use to write to and read from query file. With this binary format we save on disk space i.e reduce to 50% atleast as we are saving GFID's in binary format 16 bytes and not the string format which takes 36 bytes + We are not saving path of the file + we are also saving on ASCII delimiters. The on disk format of query record is as follows, +---------------------------------------------------------------------------+ | Length of serialized query record | Serialized Query Record | +---------------------------------------------------------------------------+ 4 bytes Length of serialized query record | | -------------------------------------------------| | | V Serialized Query Record Format: +---------------------------------------------------------------------------+ | GFID | Link count | <LINK INFO> |..... | FOOTER | +---------------------------------------------------------------------------+ 16 B 4 B Link Length 4 B | | | | -----------------------------| | | | | | V | Each <Link Info> will be serialized as | +-----------------------------------------------+ | | PGID | BASE_NAME_LENGTH | BASE_NAME | | +-----------------------------------------------+ | 16 B 4 B BASE_NAME_LENGTH | | | ------------------------------------------------------------------------| | | V FOOTER is a magic number 0xBAADF00D indicating the end of the record. This also serves as a serialized schema validator. Backport of http://review.gluster.org/#/c/12354/ > Change-Id: I9db7416fd421e118dd44eafab8b535caafe50d5a > BUG: 1272207 > Signed-off-by: Joseph Fernandes <josferna@redhat.com> > Reviewed-on: http://review.gluster.org/12354 > Reviewed-by: N Balachandran <nbalacha@redhat.com> > Tested-by: Gluster Build System <jenkins@build.gluster.com> > Reviewed-by: Dan Lambright <dlambrig@redhat.com> > Tested-by: Dan Lambright <dlambrig@redhat.com> Change-Id: I170c579027f2594a58706f826e3ddf89e34022f4 BUG: 1263619 Signed-off-by: Joseph Fernandes <josferna@redhat.com> Reviewed-on: http://review.gluster.org/12535 Tested-by: NetBSD Build System <jenkins@build.gluster.org> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Dan Lambright <dlambrig@redhat.com> Tested-by: Dan Lambright <dlambrig@redhat.com>
Diffstat (limited to 'xlators/features')
-rw-r--r--xlators/features/changetimerecorder/src/changetimerecorder.c25
-rw-r--r--xlators/features/changetimerecorder/src/ctr-helper.h2
2 files changed, 16 insertions, 11 deletions
diff --git a/xlators/features/changetimerecorder/src/changetimerecorder.c b/xlators/features/changetimerecorder/src/changetimerecorder.c
index fb337674937..c4634c16ee3 100644
--- a/xlators/features/changetimerecorder/src/changetimerecorder.c
+++ b/xlators/features/changetimerecorder/src/changetimerecorder.c
@@ -1386,15 +1386,18 @@ static int
ctr_db_query_callback (gfdb_query_record_t *gfdb_query_record,
void *args) {
int ret = -1;
- char gfid_str[UUID_CANONICAL_FORM_LEN+1] = "";
ctr_query_cbk_args_t *query_cbk_args = args;
GF_VALIDATE_OR_GOTO ("ctr", query_cbk_args, out);
- gf_uuid_unparse (gfdb_query_record->gfid, gfid_str);
- fprintf (query_cbk_args->queryFILE, "%s|%s|%ld\n", gfid_str,
- gfdb_query_record->_link_info_str,
- gfdb_query_record->link_info_size);
+ ret = gfdb_write_query_record (query_cbk_args->query_fd,
+ gfdb_query_record);
+ if (ret) {
+ gf_msg ("ctr", GF_LOG_ERROR, 0,
+ CTR_MSG_FATAL_ERROR,
+ "Failed to write to query file");
+ goto out;
+ }
query_cbk_args->count++;
@@ -1429,8 +1432,10 @@ ctr_db_query (xlator_t *this,
GF_VALIDATE_OR_GOTO (this->name, ipc_ctr_params, out);
/*Query for eligible files from db*/
- query_cbk_args.queryFILE = fopen(query_file, "a+");
- if (!query_cbk_args.queryFILE) {
+ query_cbk_args.query_fd = open (query_file,
+ O_WRONLY | O_CREAT | O_APPEND,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (query_cbk_args.query_fd < 0) {
gf_msg (this->name, GF_LOG_ERROR, errno,
CTR_MSG_FATAL_ERROR,
"Failed to open query file %s", query_file);
@@ -1494,9 +1499,9 @@ out:
if (!ret)
ret = query_cbk_args.count;
- if (query_cbk_args.queryFILE) {
- fclose (query_cbk_args.queryFILE);
- query_cbk_args.queryFILE = NULL;
+ if (query_cbk_args.query_fd >= 0) {
+ close (query_cbk_args.query_fd);
+ query_cbk_args.query_fd = -1;
}
return ret;
diff --git a/xlators/features/changetimerecorder/src/ctr-helper.h b/xlators/features/changetimerecorder/src/ctr-helper.h
index 654607fb852..e833c872881 100644
--- a/xlators/features/changetimerecorder/src/ctr-helper.h
+++ b/xlators/features/changetimerecorder/src/ctr-helper.h
@@ -37,7 +37,7 @@
typedef struct ctr_query_cbk_args {
- FILE *queryFILE;
+ int query_fd;
int count;
} ctr_query_cbk_args_t;