Changeset 87490 in webkit
- Timestamp:
- May 27, 2011 3:37:23 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r87485 r87490 1 2011-05-26 Hans Wennborg <hans@chromium.org> 2 3 Reviewed by Tony Gentilcore. 4 5 LevelDB: turn on paranoid checks and verify checksums, log errors 6 https://bugs.webkit.org/show_bug.cgi?id=61516 7 8 This allows for detection of corrupted databases. 9 Even if we can't recover from a corrupted database, discovering the 10 problem is a step in the right direction. 11 12 No new functionality, no new tests. 13 14 * platform/leveldb/LevelDBDatabase.cpp: 15 (WebCore::LevelDBDatabase::open): 16 (WebCore::LevelDBDatabase::put): 17 (WebCore::LevelDBDatabase::remove): 18 (WebCore::LevelDBDatabase::get): 19 (WebCore::LevelDBDatabase::write): 20 (WebCore::IteratorImpl::checkStatus): 21 (WebCore::IteratorImpl::seekToLast): 22 (WebCore::IteratorImpl::seek): 23 (WebCore::IteratorImpl::next): 24 (WebCore::IteratorImpl::prev): 25 (WebCore::LevelDBDatabase::createIterator): 26 1 27 2011-05-27 James Robinson <jamesr@chromium.org> 2 28 -
trunk/Source/WebCore/platform/leveldb/LevelDBDatabase.cpp
r87370 r87490 33 33 #include "LevelDBSlice.h" 34 34 #include "LevelDBWriteBatch.h" 35 #include "Logging.h" 35 36 #include <leveldb/comparator.h> 36 37 #include <leveldb/db.h> … … 99 100 OwnPtr<ComparatorAdapter> comparatorAdapter = adoptPtr(new ComparatorAdapter(comparator)); 100 101 101 OwnPtr<LevelDBDatabase> result = adoptPtr(new LevelDBDatabase);102 103 102 leveldb::Options options; 104 103 options.comparator = comparatorAdapter.get(); 105 104 options.create_if_missing = true; 105 options.paranoid_checks = true; 106 106 leveldb::DB* db; 107 leveldb::Status s = leveldb::DB::Open(options, fileName.utf8().data(), &db); 108 109 if (!s.ok()) 107 const leveldb::Status s = leveldb::DB::Open(options, fileName.utf8().data(), &db); 108 109 if (!s.ok()) { 110 LOG_ERROR("Failed to open LevelDB database from %s: %s", fileName.ascii().data(), s.ToString().c_str()); 110 111 return nullptr; 111 112 } 113 114 OwnPtr<LevelDBDatabase> result = adoptPtr(new LevelDBDatabase); 112 115 result->m_db = adoptPtr(db); 113 116 result->m_comparatorAdapter = comparatorAdapter.release(); … … 122 125 writeOptions.sync = true; 123 126 124 return m_db->Put(writeOptions, makeSlice(key), makeSlice(value)).ok(); 127 const leveldb::Status s = m_db->Put(writeOptions, makeSlice(key), makeSlice(value)); 128 if (s.ok()) 129 return true; 130 LOG_ERROR("LevelDB put failed: %s", s.ToString().c_str()); 131 return false; 125 132 } 126 133 … … 130 137 writeOptions.sync = true; 131 138 132 return m_db->Delete(writeOptions, makeSlice(key)).ok(); 139 const leveldb::Status s = m_db->Delete(writeOptions, makeSlice(key)); 140 if (s.ok()) 141 return true; 142 if (s.IsNotFound()) 143 return false; 144 LOG_ERROR("LevelDB remove failed: %s", s.ToString().c_str()); 145 return false; 133 146 } 134 147 … … 136 149 { 137 150 std::string result; 138 if (!m_db->Get(leveldb::ReadOptions(), makeSlice(key), &result).ok()) 151 leveldb::ReadOptions readOptions; 152 readOptions.verify_checksums = true; // FIXME: Disable this if the performance impact is too great. 153 154 const leveldb::Status s = m_db->Get(readOptions, makeSlice(key), &result); 155 if (s.ok()) { 156 value = makeVector(result); 157 return true; 158 } 159 if (s.IsNotFound()) 139 160 return false; 140 141 value = makeVector(result); 142 return true; 161 LOG_ERROR("LevelDB get failed: %s", s.ToString().c_str()); 162 return false; 143 163 } 144 164 … … 148 168 writeOptions.sync = true; 149 169 150 return m_db->Write(writeOptions, writeBatch.m_writeBatch.get()).ok(); 170 const leveldb::Status s = m_db->Write(writeOptions, writeBatch.m_writeBatch.get()); 171 if (s.ok()) 172 return true; 173 LOG_ERROR("LevelDB write failed: %s", s.ToString().c_str()); 174 return false; 151 175 } 152 176 … … 167 191 friend class WebCore::LevelDBDatabase; 168 192 IteratorImpl(PassOwnPtr<leveldb::Iterator>); 193 void checkStatus(); 169 194 170 195 OwnPtr<leveldb::Iterator> m_iterator; … … 177 202 } 178 203 204 void IteratorImpl::checkStatus() 205 { 206 const leveldb::Status s = m_iterator->status(); 207 if (!s.ok()) 208 LOG_ERROR("LevelDB iterator error: %s", s.ToString().c_str()); 209 } 210 179 211 bool IteratorImpl::isValid() const 180 212 { … … 185 217 { 186 218 m_iterator->SeekToLast(); 219 checkStatus(); 187 220 } 188 221 … … 190 223 { 191 224 m_iterator->Seek(makeSlice(target)); 225 checkStatus(); 192 226 } 193 227 … … 196 230 ASSERT(isValid()); 197 231 m_iterator->Next(); 232 checkStatus(); 198 233 } 199 234 … … 202 237 ASSERT(isValid()); 203 238 m_iterator->Prev(); 239 checkStatus(); 204 240 } 205 241 … … 218 254 PassOwnPtr<LevelDBIterator> LevelDBDatabase::createIterator() 219 255 { 220 OwnPtr<leveldb::Iterator> i = adoptPtr(m_db->NewIterator(leveldb::ReadOptions())); 256 leveldb::ReadOptions readOptions; 257 readOptions.verify_checksums = true; // FIXME: Disable this if the performance impact is too great. 258 OwnPtr<leveldb::Iterator> i = adoptPtr(m_db->NewIterator(readOptions)); 221 259 if (!i) // FIXME: Double check if we actually need to check this. 222 260 return nullptr;
Note: See TracChangeset
for help on using the changeset viewer.