Commit 5f2ad6d6 authored by peria@chromium.org's avatar peria@chromium.org

[SyncFS] Drop active tracker IDs in DB

It was confusing to figure a TrackerIDSets did not have active trackers
- DB had an entry with kInvalidTrackerID in value.
- DB did not have entries to figure out an active tracker.

This CL drops the first situation.


BUG=None
TEST=./unit_tests --gtest_filter="Metadata*"

Review URL: https://codereview.chromium.org/442713002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288061 0039d316-1c4b-4281-b951-d872f2087c98
parent 7a6988ee
......@@ -1008,8 +1008,8 @@ TrackerIDSet MetadataDatabaseIndexOnDisk::GetTrackerIDSetByPrefix(
std::string value;
leveldb::Status status = db_->Get(active_tracker_key, &value);
int64 active_tracker;
if (status.ok() && base::StringToInt64(value, &active_tracker) &&
active_tracker != kInvalidTrackerID) {
if (status.ok() && base::StringToInt64(value, &active_tracker)) {
DCHECK_NE(kInvalidTrackerID, active_tracker);
trackers.Activate(active_tracker);
}
......@@ -1038,30 +1038,10 @@ bool MetadataDatabaseIndexOnDisk::EraseInTrackerIDSetWithPrefix(
db_->Delete(del_key);
size_t count = 0;
scoped_ptr<LevelDBWrapper::Iterator> itr(db_->NewIterator());
for (itr->Seek(key_prefix); itr->Valid(); itr->Next()) {
const std::string key = itr->key().ToString();
if (!StartsWithASCII(key, key_prefix, true))
break;
// Entry for |del_key| is not deleted yet.
if (key == del_key)
continue;
++count;
break;
}
if (count > 0) {
// TrackerIDSet is still alive. Deactivate if the tracker is active.
leveldb::Status status =
db_->Get(active_tracker_key, &value);
int64 active_tracker_id;
if (status.ok() && base::StringToInt64(value, &active_tracker_id) &&
active_tracker_id == tracker_id) {
db_->Put(active_tracker_key, base::Int64ToString(kInvalidTrackerID));
}
} else {
// TrackerIDSet is no longer alive. Erase active tracker entry.
status = db_->Get(active_tracker_key, &value);
int64 active_tracker_id;
if (status.ok() && base::StringToInt64(value, &active_tracker_id) &&
active_tracker_id == tracker_id) {
db_->Delete(active_tracker_key);
}
......@@ -1093,7 +1073,7 @@ void MetadataDatabaseIndexOnDisk::DeactivateInTrackerIDSetWithPrefix(
int64 active_tracker_id;
if (status.ok() && base::StringToInt64(value, &active_tracker_id)) {
DCHECK(active_tracker_id == tracker_id);
db_->Put(active_tracker_key, base::Int64ToString(kInvalidTrackerID));
db_->Delete(active_tracker_key);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment