Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: sync/syncable/directory.cc

Issue 10989063: Changed DB to store node positions as Ordinals. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Changed server_position to server_ordinal in DB Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/syncable/directory.h" 5 #include "sync/syncable/directory.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/perftimer.h" 8 #include "base/perftimer.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "sync/internal_api/public/base/node_ordinal.h"
11 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" 12 #include "sync/internal_api/public/util/unrecoverable_error_handler.h"
12 #include "sync/syncable/base_transaction.h" 13 #include "sync/syncable/base_transaction.h"
13 #include "sync/syncable/entry.h" 14 #include "sync/syncable/entry.h"
14 #include "sync/syncable/entry_kernel.h" 15 #include "sync/syncable/entry_kernel.h"
15 #include "sync/syncable/in_memory_directory_backing_store.h" 16 #include "sync/syncable/in_memory_directory_backing_store.h"
16 #include "sync/syncable/on_disk_directory_backing_store.h" 17 #include "sync/syncable/on_disk_directory_backing_store.h"
17 #include "sync/syncable/read_transaction.h" 18 #include "sync/syncable/read_transaction.h"
18 #include "sync/syncable/scoped_index_updater.h" 19 #include "sync/syncable/scoped_index_updater.h"
19 #include "sync/syncable/syncable-inl.h" 20 #include "sync/syncable/syncable-inl.h"
20 #include "sync/syncable/syncable_changes_version.h" 21 #include "sync/syncable/syncable_changes_version.h"
(...skipping 22 matching lines...) Expand all
43 return !a->ref(UNIQUE_CLIENT_TAG).empty(); 44 return !a->ref(UNIQUE_CLIENT_TAG).empty();
44 } 45 }
45 46
46 bool ParentIdAndHandleIndexer::Comparator::operator() ( 47 bool ParentIdAndHandleIndexer::Comparator::operator() (
47 const syncable::EntryKernel* a, 48 const syncable::EntryKernel* a,
48 const syncable::EntryKernel* b) const { 49 const syncable::EntryKernel* b) const {
49 int cmp = a->ref(PARENT_ID).compare(b->ref(PARENT_ID)); 50 int cmp = a->ref(PARENT_ID).compare(b->ref(PARENT_ID));
50 if (cmp != 0) 51 if (cmp != 0)
51 return cmp < 0; 52 return cmp < 0;
52 53
53 int64 a_position = a->ref(SERVER_POSITION_IN_PARENT); 54 NodeOrdinal a_position = a->ref(SERVER_ORDINAL_IN_PARENT);
akalin 2012/10/05 00:57:59 use const ref
vishwath 2012/10/05 18:34:49 Done.
54 int64 b_position = b->ref(SERVER_POSITION_IN_PARENT); 55 NodeOrdinal b_position = b->ref(SERVER_ORDINAL_IN_PARENT);
akalin 2012/10/05 00:57:59 here too
vishwath 2012/10/05 18:34:49 Done.
55 if (a_position != b_position) 56 if (!a_position.Equals(b_position))
56 return a_position < b_position; 57 return a_position.LessThan(b_position);
57 58
58 cmp = a->ref(ID).compare(b->ref(ID)); 59 cmp = a->ref(ID).compare(b->ref(ID));
59 return cmp < 0; 60 return cmp < 0;
60 } 61 }
61 62
62 // static 63 // static
63 bool ParentIdAndHandleIndexer::ShouldInclude(const EntryKernel* a) { 64 bool ParentIdAndHandleIndexer::ShouldInclude(const EntryKernel* a) {
64 // This index excludes deleted items and the root item. The root 65 // This index excludes deleted items and the root item. The root
65 // item is excluded so that it doesn't show up as a child of itself. 66 // item is excluded so that it doesn't show up as a child of itself.
66 return !a->ref(IS_DEL) && !a->ref(ID).IsRoot(); 67 return !a->ref(IS_DEL) && !a->ref(ID).IsRoot();
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 return true; 1126 return true;
1126 } 1127 }
1127 1128
1128 Id Directory::ComputePrevIdFromServerPosition( 1129 Id Directory::ComputePrevIdFromServerPosition(
1129 const EntryKernel* entry, 1130 const EntryKernel* entry,
1130 const syncable::Id& parent_id) { 1131 const syncable::Id& parent_id) {
1131 ScopedKernelLock lock(this); 1132 ScopedKernelLock lock(this);
1132 1133
1133 // Find the natural insertion point in the parent_id_child_index, and 1134 // Find the natural insertion point in the parent_id_child_index, and
1134 // work back from there, filtering out ineligible candidates. 1135 // work back from there, filtering out ineligible candidates.
1135 ParentIdChildIndex::iterator sibling = LocateInParentChildIndex(lock, 1136 ParentIdChildIndex::iterator sibling = LocateInParentChildIndex(
1136 parent_id, entry->ref(SERVER_POSITION_IN_PARENT), entry->ref(ID)); 1137 lock,
1138 parent_id,
1139 NodeOrdinalToInt64(entry->ref(SERVER_ORDINAL_IN_PARENT)),
1140 entry->ref(ID));
1137 ParentIdChildIndex::iterator first_sibling = 1141 ParentIdChildIndex::iterator first_sibling =
1138 GetParentChildIndexLowerBound(lock, parent_id); 1142 GetParentChildIndexLowerBound(lock, parent_id);
1139 1143
1140 while (sibling != first_sibling) { 1144 while (sibling != first_sibling) {
1141 --sibling; 1145 --sibling;
1142 EntryKernel* candidate = *sibling; 1146 EntryKernel* candidate = *sibling;
1143 1147
1144 // The item itself should never be in the range under consideration. 1148 // The item itself should never be in the range under consideration.
1145 DCHECK_NE(candidate->ref(META_HANDLE), entry->ref(META_HANDLE)); 1149 DCHECK_NE(candidate->ref(META_HANDLE), entry->ref(META_HANDLE));
1146 1150
(...skipping 22 matching lines...) Expand all
1169 // This item will be the first in the sibling order. 1173 // This item will be the first in the sibling order.
1170 return Id(); 1174 return Id();
1171 } 1175 }
1172 1176
1173 Directory::ParentIdChildIndex::iterator Directory::LocateInParentChildIndex( 1177 Directory::ParentIdChildIndex::iterator Directory::LocateInParentChildIndex(
1174 const ScopedKernelLock& lock, 1178 const ScopedKernelLock& lock,
1175 const Id& parent_id, 1179 const Id& parent_id,
1176 int64 position_in_parent, 1180 int64 position_in_parent,
1177 const Id& item_id_for_tiebreaking) { 1181 const Id& item_id_for_tiebreaking) {
1178 kernel_->needle.put(PARENT_ID, parent_id); 1182 kernel_->needle.put(PARENT_ID, parent_id);
1179 kernel_->needle.put(SERVER_POSITION_IN_PARENT, position_in_parent); 1183 kernel_->needle.put(SERVER_ORDINAL_IN_PARENT,
1184 Int64ToNodeOrdinal(position_in_parent));
1180 kernel_->needle.put(ID, item_id_for_tiebreaking); 1185 kernel_->needle.put(ID, item_id_for_tiebreaking);
1181 return kernel_->parent_id_child_index->lower_bound(&kernel_->needle); 1186 return kernel_->parent_id_child_index->lower_bound(&kernel_->needle);
1182 } 1187 }
1183 1188
1184 Directory::ParentIdChildIndex::iterator 1189 Directory::ParentIdChildIndex::iterator
1185 Directory::GetParentChildIndexLowerBound(const ScopedKernelLock& lock, 1190 Directory::GetParentChildIndexLowerBound(const ScopedKernelLock& lock,
1186 const Id& parent_id) { 1191 const Id& parent_id) {
1187 // Peg the parent ID, and use the least values for the remaining 1192 // Peg the parent ID, and use the least values for the remaining
1188 // index variables. 1193 // index variables.
1189 return LocateInParentChildIndex(lock, parent_id, 1194 return LocateInParentChildIndex(lock, parent_id,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 // There were no children in the linked list. 1239 // There were no children in the linked list.
1235 return NULL; 1240 return NULL;
1236 } 1241 }
1237 1242
1238 ScopedKernelLock::ScopedKernelLock(const Directory* dir) 1243 ScopedKernelLock::ScopedKernelLock(const Directory* dir)
1239 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { 1244 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) {
1240 } 1245 }
1241 1246
1242 } // namespace syncable 1247 } // namespace syncable
1243 } // namespace syncer 1248 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698