| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.LevelDB.FreeDi
skSpaceFailure", 1/*sample*/, 2/*boundary*/); | 152 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.LevelDB.FreeDi
skSpaceFailure", 1/*sample*/, 2/*boundary*/); |
| 153 return; | 153 return; |
| 154 } | 154 } |
| 155 int clampedDiskSpaceKBytes = freeDiskSpaceInKBytes > INT_MAX ? INT_MAX : fre
eDiskSpaceInKBytes; | 155 int clampedDiskSpaceKBytes = freeDiskSpaceInKBytes > INT_MAX ? INT_MAX : fre
eDiskSpaceInKBytes; |
| 156 const uint64_t histogramMax = static_cast<uint64_t>(1e9); | 156 const uint64_t histogramMax = static_cast<uint64_t>(1e9); |
| 157 COMPILE_ASSERT(histogramMax <= INT_MAX, histogramMaxTooBig); | 157 COMPILE_ASSERT(histogramMax <= INT_MAX, histogramMaxTooBig); |
| 158 HistogramSupport::histogramCustomCounts(name.utf8().data(), clampedDiskSpace
KBytes, 1, histogramMax, 11/*buckets*/); | 158 HistogramSupport::histogramCustomCounts(name.utf8().data(), clampedDiskSpace
KBytes, 1, histogramMax, 11/*buckets*/); |
| 159 #endif | 159 #endif |
| 160 } | 160 } |
| 161 | 161 |
| 162 static void histogramLevelDBError(const char* histogramName, const leveldb::Stat
us& s) |
| 163 { |
| 164 ASSERT(!s.ok()); |
| 165 enum { |
| 166 LevelDBNotFound, |
| 167 LevelDBCorruption, |
| 168 LevelDBIOError, |
| 169 LevelDBOther, |
| 170 LevelDBMaxError |
| 171 }; |
| 172 int levelDBError = LevelDBOther; |
| 173 if (s.IsNotFound()) |
| 174 levelDBError = LevelDBNotFound; |
| 175 else if (s.IsCorruption()) |
| 176 levelDBError = LevelDBCorruption; |
| 177 else if (s.IsIOError()) |
| 178 levelDBError = LevelDBIOError; |
| 179 HistogramSupport::histogramEnumeration(histogramName, levelDBError, LevelDBM
axError); |
| 180 } |
| 181 |
| 162 PassOwnPtr<LevelDBDatabase> LevelDBDatabase::open(const String& fileName, const
LevelDBComparator* comparator) | 182 PassOwnPtr<LevelDBDatabase> LevelDBDatabase::open(const String& fileName, const
LevelDBComparator* comparator) |
| 163 { | 183 { |
| 164 OwnPtr<ComparatorAdapter> comparatorAdapter = adoptPtr(new ComparatorAdapter
(comparator)); | 184 OwnPtr<ComparatorAdapter> comparatorAdapter = adoptPtr(new ComparatorAdapter
(comparator)); |
| 165 | 185 |
| 166 leveldb::DB* db; | 186 leveldb::DB* db; |
| 167 const leveldb::Status s = openDB(comparatorAdapter.get(), leveldb::IDBEnv(),
fileName, &db); | 187 const leveldb::Status s = openDB(comparatorAdapter.get(), leveldb::IDBEnv(),
fileName, &db); |
| 168 | 188 |
| 169 if (!s.ok()) { | 189 if (!s.ok()) { |
| 170 enum { | 190 histogramLevelDBError("WebCore.IndexedDB.LevelDBOpenErrors", s); |
| 171 LevelDBNotFound, | |
| 172 LevelDBCorruption, | |
| 173 LevelDBIOError, | |
| 174 LevelDBOther, | |
| 175 LevelDBMaxError | |
| 176 }; | |
| 177 int levelDBError = LevelDBOther; | |
| 178 if (s.IsNotFound()) | |
| 179 levelDBError = LevelDBNotFound; | |
| 180 else if (s.IsCorruption()) | |
| 181 levelDBError = LevelDBCorruption; | |
| 182 else if (s.IsIOError()) | |
| 183 levelDBError = LevelDBIOError; | |
| 184 HistogramSupport::histogramEnumeration("WebCore.IndexedDB.LevelDBOpenErr
ors", levelDBError, LevelDBMaxError); | |
| 185 | |
| 186 histogramFreeSpace("Failure", fileName); | 191 histogramFreeSpace("Failure", fileName); |
| 187 | 192 |
| 188 LOG_ERROR("Failed to open LevelDB database from %s: %s", fileName.ascii(
).data(), s.ToString().c_str()); | 193 LOG_ERROR("Failed to open LevelDB database from %s: %s", fileName.ascii(
).data(), s.ToString().c_str()); |
| 189 return nullptr; | 194 return nullptr; |
| 190 } | 195 } |
| 191 | 196 |
| 192 histogramFreeSpace("Success", fileName); | 197 histogramFreeSpace("Success", fileName); |
| 193 | 198 |
| 194 OwnPtr<LevelDBDatabase> result = adoptPtr(new LevelDBDatabase); | 199 OwnPtr<LevelDBDatabase> result = adoptPtr(new LevelDBDatabase); |
| 195 result->m_db = adoptPtr(db); | 200 result->m_db = adoptPtr(db); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 274 } |
| 270 | 275 |
| 271 bool LevelDBDatabase::write(LevelDBWriteBatch& writeBatch) | 276 bool LevelDBDatabase::write(LevelDBWriteBatch& writeBatch) |
| 272 { | 277 { |
| 273 leveldb::WriteOptions writeOptions; | 278 leveldb::WriteOptions writeOptions; |
| 274 writeOptions.sync = true; | 279 writeOptions.sync = true; |
| 275 | 280 |
| 276 const leveldb::Status s = m_db->Write(writeOptions, writeBatch.m_writeBatch.
get()); | 281 const leveldb::Status s = m_db->Write(writeOptions, writeBatch.m_writeBatch.
get()); |
| 277 if (s.ok()) | 282 if (s.ok()) |
| 278 return true; | 283 return true; |
| 284 histogramLevelDBError("WebCore.IndexedDB.LevelDBWriteErrors", s); |
| 279 LOG_ERROR("LevelDB write failed: %s", s.ToString().c_str()); | 285 LOG_ERROR("LevelDB write failed: %s", s.ToString().c_str()); |
| 280 return false; | 286 return false; |
| 281 } | 287 } |
| 282 | 288 |
| 283 namespace { | 289 namespace { |
| 284 class IteratorImpl : public LevelDBIterator { | 290 class IteratorImpl : public LevelDBIterator { |
| 285 public: | 291 public: |
| 286 ~IteratorImpl() { }; | 292 ~IteratorImpl() { }; |
| 287 | 293 |
| 288 virtual bool isValid() const; | 294 virtual bool isValid() const; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 } | 375 } |
| 370 | 376 |
| 371 const LevelDBComparator* LevelDBDatabase::comparator() const | 377 const LevelDBComparator* LevelDBDatabase::comparator() const |
| 372 { | 378 { |
| 373 return m_comparator; | 379 return m_comparator; |
| 374 } | 380 } |
| 375 | 381 |
| 376 } | 382 } |
| 377 | 383 |
| 378 #endif | 384 #endif |
| OLD | NEW |