Ticket #455: bug-455-fix.patch
File bug-455-fix.patch, 4.6 KB (added by , 15 years ago) |
---|
-
backends/chert/chert_cursor.cc
55 55 is_after_end(false), 56 56 tag_status(UNREAD), 57 57 B(B_), 58 version(B_->cursor_version), 58 59 level(B_->level) 59 60 { 61 B->cursor_created_since_last_modification = true; 60 62 C = new Cursor[level + 1]; 61 63 62 64 for (int j = 0; j < level; j++) { … … 67 69 C[level].p = B->C[level].p; 68 70 } 69 71 72 void 73 ChertCursor::resize() 74 { 75 int new_level = B->level; 76 if (new_level <= level) { 77 for (int i = 0; i < new_level; i++) { 78 C[i].n = BLK_UNUSED; 79 } 80 for (int j = new_level; j < level; ++j) { 81 delete C[j].p; 82 } 83 } else { 84 Cursor * old_C = C; 85 C = new Cursor[new_level + 1]; 86 for (int i = 0; i < level; i++) { 87 C[i].p = old_C[i].p; 88 C[i].n = BLK_UNUSED; 89 } 90 delete old_C; 91 for (int j = level; j < new_level; j++) { 92 C[j].p = new byte[B->block_size]; 93 C[j].n = BLK_UNUSED; 94 } 95 } 96 level = new_level; 97 C[level].n = B->C[level].n; 98 C[level].p = B->C[level].p; 99 version = B->cursor_version; 100 } 101 70 102 ChertCursor::~ChertCursor() 71 103 { 72 104 // Use the value of level stored in the cursor rather than the … … 81 113 ChertCursor::prev() 82 114 { 83 115 DEBUGCALL(DB, bool, "ChertCursor::prev", ""); 84 Assert(B->level <= level);85 116 Assert(!is_after_end); 117 if (B->cursor_version != version) { 118 resize(); 119 is_positioned = false; 120 } 86 121 87 122 if (!is_positioned) { 88 123 // We've read the last key and tag, and we're now not positioned. … … 126 161 ChertCursor::next() 127 162 { 128 163 DEBUGCALL(DB, bool, "ChertCursor::next", ""); 129 Assert(B->level <= level);130 164 Assert(!is_after_end); 165 if (B->cursor_version != version) { 166 resize(); 167 (void)find_entry(current_key); 168 } 169 131 170 if (tag_status == UNREAD) { 132 171 while (true) { 133 172 if (! B->next(C, 0)) { … … 157 196 ChertCursor::find_entry(const string &key) 158 197 { 159 198 DEBUGCALL(DB, bool, "ChertCursor::find_entry", key); 160 Assert(B->level <= level); 199 if (B->cursor_version != version) { 200 resize(); 201 } 161 202 162 203 is_after_end = false; 163 204 … … 203 244 ChertCursor::find_entry_ge(const string &key) 204 245 { 205 246 DEBUGCALL(DB, bool, "ChertCursor::find_entry_ge", key); 206 Assert(B->level <= level); 247 if (B->cursor_version != version) { 248 resize(); 249 } 207 250 208 251 is_after_end = false; 209 252 -
backends/chert/chert_table.h
732 732 /// Set to true when the database is opened to write. 733 733 bool writable; 734 734 735 /// Flag for tracking when cursors need to rebuild. 736 mutable bool cursor_created_since_last_modification; 737 738 /// Version count for tracking when cursors need to rebuild. 739 unsigned long cursor_version; 740 735 741 /* B-tree navigation functions */ 736 742 bool prev(Cursor *C_, int j) const { 737 743 if (sequential) return prev_for_sequential(C_, j); -
backends/chert/chert_cursor.h
72 72 /// Assignment not allowed 73 73 ChertCursor & operator=(const ChertCursor &); 74 74 75 void resize(); 76 75 77 protected: 76 78 /** Whether the cursor is positioned at a valid entry. 77 79 * … … 96 98 /// Pointer to an array of Cursors 97 99 Cursor * C; 98 100 101 unsigned long version; 102 99 103 /** The value of level in the Btree structure. */ 100 104 int level; 101 105 -
backends/chert/chert_table.cc
1138 1138 } 1139 1139 if (!replacement) ++item_count; 1140 1140 Btree_modified = true; 1141 if (cursor_created_since_last_modification) { 1142 cursor_created_since_last_modification = false; 1143 ++cursor_version; 1144 } 1141 1145 } 1142 1146 1143 1147 /* ChertTable::del(key) returns false if the key is not in the B-tree, … … 1175 1179 1176 1180 item_count--; 1177 1181 Btree_modified = true; 1182 if (cursor_created_since_last_modification) { 1183 cursor_created_since_last_modification = false; 1184 ++cursor_version; 1185 } 1178 1186 RETURN(true); 1179 1187 } 1180 1188 … … 1579 1587 Btree_modified(false), 1580 1588 full_compaction(false), 1581 1589 writable(!readonly_), 1590 cursor_created_since_last_modification(false), 1591 cursor_version(0), 1582 1592 split_p(0), 1583 1593 compress_strategy(compress_strategy_), 1584 1594 deflate_zstream(NULL),