Kouhei Sutou
null+****@clear*****
Wed Jun 24 23:01:41 JST 2015
Kouhei Sutou 2015-06-24 23:01:41 +0900 (Wed, 24 Jun 2015) New Revision: 873fb651de23f944817b725b50bc5eedeb387206 https://github.com/groonga/groonga/commit/873fb651de23f944817b725b50bc5eedeb387206 Message: Support flushing GRN_TABLE_DAT Modified files: lib/dat.cpp lib/dat/file-impl.cpp lib/dat/file-impl.hpp lib/dat/file.cpp lib/dat/file.hpp lib/dat/trie.cpp lib/dat/trie.hpp lib/db.c lib/grn_dat.h Modified: lib/dat.cpp (+31 -1) =================================================================== --- lib/dat.cpp 2015-06-24 22:29:42 +0900 (60588d5) +++ lib/dat.cpp 2015-06-24 23:01:41 +0900 (51a84da) @@ -1,5 +1,5 @@ /* -*- c-basic-offset: 2 -*- */ -/* Copyright(C) 2011-2014 Brazil +/* Copyright(C) 2011-2015 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -1112,4 +1112,34 @@ grn_dat_repair(grn_ctx *ctx, grn_dat *dat) return GRN_SUCCESS; } +grn_rc +grn_dat_flush(grn_ctx *ctx, grn_dat *dat) +{ + if (!dat->io) { + return GRN_SUCCESS; + } + + grn_rc rc = grn_io_flush(ctx, dat->io); + if (rc != GRN_SUCCESS) { + return rc; + } + + if (dat->trie) { + grn::dat::Trie * const trie = static_cast<grn::dat::Trie *>(dat->trie); + try { + trie->flush(); + } catch (const grn::dat::Exception &ex) { + const grn_rc error_code = grn_dat_translate_error_code(ex.code()); + if (error_code == GRN_INPUT_OUTPUT_ERROR) { + SERR("grn::dat::Trie::flush failed"); + } else { + ERR(error_code, "grn::dat::Trie::flush failed"); + } + return error_code; + } + } + + return GRN_SUCCESS; +} + } // extern "C" Modified: lib/dat/file-impl.cpp (+19 -1) =================================================================== --- lib/dat/file-impl.cpp 2015-06-24 22:29:42 +0900 (3643a80) +++ lib/dat/file-impl.cpp 2015-06-24 23:01:41 +0900 (7a9879a) @@ -1,5 +1,5 @@ /* -*- c-basic-offset: 2 -*- */ -/* Copyright(C) 2011 Brazil +/* Copyright(C) 2011-2015 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -123,6 +123,15 @@ void FileImpl::swap(FileImpl *rhs) { std::swap(addr_, rhs->addr_); } +void FileImpl::flush() { + if (!addr_) { + return; + } + + BOOL succeeded = ::FlushViewOfFile(addr_, size_); + GRN_DAT_THROW_IF(IO_ERROR, !succeeded); +} + void FileImpl::create_(const char *path, UInt64 size) { if ((path != NULL) && (path[0] != '\0')) { file_ = ::CreateFileA(path, GRN_IO_FILE_CREATE_MODE, @@ -193,6 +202,15 @@ void FileImpl::swap(FileImpl *rhs) { std::swap(length_, rhs->length_); } +void FileImpl::flush() { + if (!addr_) { + return; + } + + int result = ::msync(addr_, length_, MS_SYNC); + GRN_DAT_THROW_IF(IO_ERROR, result != 0); +} + void FileImpl::create_(const char *path, UInt64 size) { GRN_DAT_THROW_IF(PARAM_ERROR, size > static_cast<UInt64>(std::numeric_limits< ::off_t>::max())); Modified: lib/dat/file-impl.hpp (+3 -1) =================================================================== --- lib/dat/file-impl.hpp 2015-06-24 22:29:42 +0900 (f4e0543) +++ lib/dat/file-impl.hpp 2015-06-24 23:01:41 +0900 (245dbfc) @@ -1,5 +1,5 @@ /* -*- c-basic-offset: 2 -*- */ -/* Copyright(C) 2011-2012 Brazil +/* Copyright(C) 2011-2015 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -45,6 +45,8 @@ class FileImpl { void swap(FileImpl *rhs); + void flush(); + private: void *ptr_; UInt64 size_; Modified: lib/dat/file.cpp (+7 -1) =================================================================== --- lib/dat/file.cpp 2015-06-24 22:29:42 +0900 (57bfcb9) +++ lib/dat/file.cpp 2015-06-24 23:01:41 +0900 (82d6159) @@ -1,5 +1,5 @@ /* -*- c-basic-offset: 2 -*- */ -/* Copyright(C) 2011 Brazil +/* Copyright(C) 2011-2015 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -63,5 +63,11 @@ void File::swap(File *rhs) { rhs->impl_ = temp; } +void File::flush() { + if (impl_) { + impl_->flush(); + } +} + } // namespace dat } // namespace grn Modified: lib/dat/file.hpp (+3 -1) =================================================================== --- lib/dat/file.hpp 2015-06-24 22:29:42 +0900 (c2be8d8) +++ lib/dat/file.hpp 2015-06-24 23:01:41 +0900 (e7dda0e) @@ -1,5 +1,5 @@ /* -*- c-basic-offset: 2 -*- */ -/* Copyright(C) 2011 Brazil +/* Copyright(C) 2011-2015 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -46,6 +46,8 @@ class GRN_DAT_API File { void swap(File *rhs); + void flush(); + private: FileImpl *impl_; Modified: lib/dat/trie.cpp (+5 -1) =================================================================== --- lib/dat/trie.cpp 2015-06-24 22:29:42 +0900 (82c8c27) +++ lib/dat/trie.cpp 2015-06-24 23:01:41 +0900 (2f9e79b) @@ -1,5 +1,5 @@ /* -*- c-basic-offset: 2 -*- */ -/* Copyright(C) 2011 Brazil +/* Copyright(C) 2011-2015 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -168,6 +168,10 @@ void Trie::swap(Trie *trie) { key_buf_.swap(&trie->key_buf_); } +void Trie::flush() { + file_.flush(); +} + void Trie::create_file(const char *file_name, UInt64 file_size, UInt32 max_num_keys, Modified: lib/dat/trie.hpp (+3 -1) =================================================================== --- lib/dat/trie.hpp 2015-06-24 22:29:42 +0900 (6bd307b) +++ lib/dat/trie.hpp 2015-06-24 23:01:41 +0900 (8a272bb) @@ -1,5 +1,5 @@ /* -*- c-basic-offset: 2 -*- */ -/* Copyright(C) 2011 Brazil +/* Copyright(C) 2011-2015 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -189,6 +189,8 @@ class GRN_DAT_API Trie { header_->set_status_flags(status_flags() & ~CHANGING_MASK); } + void flush(); + private: File file_; Header *header_; Modified: lib/db.c (+13 -5) =================================================================== --- lib/db.c 2015-06-24 22:29:42 +0900 (96bc4d7) +++ lib/db.c 2015-06-24 23:01:41 +0900 (7bc41a9) @@ -9739,14 +9739,22 @@ grn_obj_flush(grn_ctx *ctx, grn_obj *obj) { grn_rc rc = GRN_SUCCESS; GRN_API_ENTER; - if (obj->header.type == GRN_DB) { - rc = grn_io_flush(ctx, grn_obj_io(obj)); - if (rc == GRN_SUCCESS) { + switch (obj->header.type) { + case GRN_DB : + { grn_db *db = (grn_db *)obj; - rc = grn_obj_flush(ctx, (grn_obj *)(db->specs)); + rc = grn_obj_flush(ctx, db->keys); + if (rc == GRN_SUCCESS) { + rc = grn_obj_flush(ctx, (grn_obj *)(db->specs)); + } } - } else { + break; + case GRN_TABLE_DAT_KEY : + rc = grn_dat_flush(ctx, (grn_dat *)obj); + break; + default : rc = grn_io_flush(ctx, grn_obj_io(obj)); + break; } GRN_API_RETURN(rc); } Modified: lib/grn_dat.h (+3 -1) =================================================================== --- lib/grn_dat.h 2015-06-24 22:29:42 +0900 (aefd044) +++ lib/grn_dat.h 2015-06-24 23:01:41 +0900 (d3c768f) @@ -1,5 +1,5 @@ /* -*- c-basic-offset: 2 -*- */ -/* Copyright(C) 2011-2014 Brazil +/* Copyright(C) 2011-2015 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -79,6 +79,8 @@ GRN_API grn_rc grn_dat_clear_status_flags(grn_ctx *ctx, grn_dat *dat); */ GRN_API grn_rc grn_dat_repair(grn_ctx *ctx, grn_dat *dat); +GRN_API grn_rc grn_dat_flush(grn_ctx *ctx, grn_dat *dat); + #ifdef __cplusplus } #endif -------------- next part -------------- HTML����������������������������...Download