[Groonga-commit] groonga/grnxx [master] Fix a bug of grnxx::db::BlobVector::defrag().

Back to archive index

susumu.yata null+****@clear*****
Thu Dec 20 16:28:41 JST 2012


susumu.yata	2012-12-20 16:28:41 +0900 (Thu, 20 Dec 2012)

  New Revision: a901a206abe1ea4f94944cf11b1333f9569c8455
  https://github.com/groonga/grnxx/commit/a901a206abe1ea4f94944cf11b1333f9569c8455

  Log:
    Fix a bug of grnxx::db::BlobVector::defrag().

  Modified files:
    lib/db/blob_vector.cpp

  Modified: lib/db/blob_vector.cpp (+9 -2)
===================================================================
--- lib/db/blob_vector.cpp    2012-12-20 10:56:04 +0900 (2287d1e)
+++ lib/db/blob_vector.cpp    2012-12-20 16:28:41 +0900 (4819cda)
@@ -131,11 +131,18 @@ void BlobVectorImpl::prepend(uint64_t id, const Blob &value) {
 
 void BlobVectorImpl::defrag() {
   // TODO: To be more efficient.
-  table_.scan([this](uint64_t id, BlobVectorCell *cell) -> bool {
+  table_.scan([this](uint64_t, BlobVectorCell *cell) -> bool {
     if (cell->type() != BLOB_VECTOR_MEDIUM) {
       return true;
     }
-    set_value(id, get_value(*cell));
+
+    const BlobVectorCell old_cell = *cell;
+    const BlobVectorCell new_cell = create_value(get_value(old_cell));
+    if (atomic_compare_and_swap(old_cell, new_cell, cell)) {
+      free_value(old_cell);
+    } else {
+      free_value(new_cell);
+    }
     return true;
   });
 }
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index