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

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/metadata_database.cc

Issue 527163002: [SyncFS] Retry initialization of MetadataDatabase on failure of loading ServiceMetadata (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Retry initialization Created 6 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/sync_file_system/drive_backend/metadata_database.h" 5 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <stack> 8 #include <stack>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 // static 1417 // static
1418 void MetadataDatabase::CreateOnWorkerTaskRunner( 1418 void MetadataDatabase::CreateOnWorkerTaskRunner(
1419 scoped_ptr<CreateParam> create_param, 1419 scoped_ptr<CreateParam> create_param,
1420 const CreateCallback& callback) { 1420 const CreateCallback& callback) {
1421 DCHECK(create_param->worker_task_runner->RunsTasksOnCurrentThread()); 1421 DCHECK(create_param->worker_task_runner->RunsTasksOnCurrentThread());
1422 1422
1423 scoped_ptr<MetadataDatabase> metadata_database( 1423 scoped_ptr<MetadataDatabase> metadata_database(
1424 new MetadataDatabase(create_param->worker_task_runner, 1424 new MetadataDatabase(create_param->worker_task_runner,
1425 create_param->database_path, 1425 create_param->database_path,
1426 create_param->env_override)); 1426 create_param->env_override));
1427
1427 SyncStatusCode status = metadata_database->Initialize(); 1428 SyncStatusCode status = metadata_database->Initialize();
1429 // Retry to initialize database, if the initialization fails.
1430 for (int i = 0; i < kMaxRetry && status != SYNC_STATUS_OK; ++i) {
tzik 2014/09/03 04:47:37 I think 2 is enough for the number of retry. Can
peria 2014/09/03 09:24:21 Done.
1431 metadata_database.reset(
1432 new MetadataDatabase(create_param->worker_task_runner,
1433 create_param->database_path,
1434 create_param->env_override));
1435 status = metadata_database->Initialize();
1436 }
1437
1428 if (status != SYNC_STATUS_OK) 1438 if (status != SYNC_STATUS_OK)
1429 metadata_database.reset(); 1439 metadata_database.reset();
1430 1440
1431 metadata_database->DetachFromSequence(); 1441 if (metadata_database)
1442 metadata_database->DetachFromSequence();
1432 create_param->worker_task_runner->PostTask( 1443 create_param->worker_task_runner->PostTask(
1433 FROM_HERE, 1444 FROM_HERE,
1434 base::Bind( 1445 base::Bind(
1435 callback, status, base::Passed(&metadata_database))); 1446 callback, status, base::Passed(&metadata_database)));
1436 } 1447 }
1437 1448
1438 SyncStatusCode MetadataDatabase::Initialize() { 1449 SyncStatusCode MetadataDatabase::Initialize() {
1439 base::ThreadRestrictions::AssertIOAllowed(); 1450 base::ThreadRestrictions::AssertIOAllowed();
1440 DCHECK(worker_sequence_checker_.CalledOnValidSequencedThread()); 1451 DCHECK(worker_sequence_checker_.CalledOnValidSequencedThread());
1441 1452
(...skipping 11 matching lines...) Expand all
1453 if (status != SYNC_STATUS_OK) 1464 if (status != SYNC_STATUS_OK)
1454 return status; 1465 return status;
1455 } 1466 }
1456 1467
1457 if (CommandLine::ForCurrentProcess()->HasSwitch( 1468 if (CommandLine::ForCurrentProcess()->HasSwitch(
1458 kEnableMetadataDatabaseOnDisk)) { 1469 kEnableMetadataDatabaseOnDisk)) {
1459 index_ = MetadataDatabaseIndexOnDisk::Create(db_.get()); 1470 index_ = MetadataDatabaseIndexOnDisk::Create(db_.get());
1460 } else { 1471 } else {
1461 index_ = MetadataDatabaseIndex::Create(db_.get()); 1472 index_ = MetadataDatabaseIndex::Create(db_.get());
1462 } 1473 }
1474 if (!index_) {
1475 // Delete all entries in |db_| to reset it.
1476 // TODO(peria): Make LevelDBWrapper::DestroyDB() to avoid a full scan.
1477 scoped_ptr<LevelDBWrapper::Iterator> itr = db_->NewIterator();
1478 for (itr->SeekToFirst(); itr->Valid();)
1479 itr->Delete();
1480 db_->Commit();
1481
1482 return SYNC_DATABASE_ERROR_FAILED;
1483 }
1463 1484
1464 status = LevelDBStatusToSyncStatusCode(db_->Commit()); 1485 status = LevelDBStatusToSyncStatusCode(db_->Commit());
1465 if (status != SYNC_STATUS_OK) 1486 if (status != SYNC_STATUS_OK)
1466 return status; 1487 return status;
1467 1488
1468 UpdateLargestKnownChangeID(index_->GetLargestChangeID()); 1489 UpdateLargestKnownChangeID(index_->GetLargestChangeID());
1469 1490
1470 return status; 1491 return status;
1471 } 1492 }
1472 1493
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1954 return false; 1975 return false;
1955 1976
1956 if (!parents.empty()) 1977 if (!parents.empty())
1957 return false; 1978 return false;
1958 1979
1959 return true; 1980 return true;
1960 } 1981 }
1961 1982
1962 } // namespace drive_backend 1983 } // namespace drive_backend
1963 } // namespace sync_file_system 1984 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698