Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Commit af21830

Browse files
committed
improve error handling
shrink minimum commit size further
1 parent 7cb71b0 commit af21830

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/cache_manager.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@ void UnqliteHandleResult(std::string operation, unqlite* database, int ret) {
5858
const char* zBuf;
5959
int iLen;
6060
unqlite_config(database, UNQLITE_CONFIG_ERR_LOG, &zBuf, &iLen);
61-
LOG_S(WARNING) << "Unqlite error: \"" << std::string(zBuf, zBuf + iLen)
62-
<< "\". Rolling back.";
63-
unqlite_rollback(database);
61+
LOG_S(WARNING) << "Unqlite error: \"" << std::string(zBuf, zBuf + iLen) << "\".";
62+
63+
switch(ret) {
64+
case UNQLITE_IOERR:
65+
case UNQLITE_NOMEM:
66+
LOG_S(ERROR) << "Rolling back the last commit.";
67+
unqlite_rollback(database);
68+
}
6469
}
6570
}
6671

@@ -107,9 +112,10 @@ struct UnqliteCacheDriver : public ICacheStore {
107112
{
108113
bytesSinceCommit_ += value.size();
109114

110-
if (bytesSinceCommit_ > 32*1024*1024)
115+
if (bytesSinceCommit_ > 16*1024*1024)
111116
{
112117
ret = unqlite_commit(database_);
118+
UnqliteHandleResult("unqlite_commit", database_, ret);
113119
if (ret == UNQLITE_OK) bytesSinceCommit_ = 0u;
114120
}
115121
}
@@ -254,10 +260,7 @@ std::shared_ptr<ICacheStore> OpenOrConnectUnqliteStore(
254260
<< "\".";
255261

256262
int ret = unqlite_open(&database, databaseFile.c_str(), UNQLITE_OPEN_CREATE);
257-
258-
if (ret != UNQLITE_OK)
259-
LOG_S(WARNING) << "Unqlite: unqlite_open reported error condition " << ret
260-
<< ".";
263+
UnqliteHandleResult("unqlite_open", database, ret);
261264

262265
// if (ret == UNQLITE_OK) return
263266
// std::make_shared<UnqliteCacheDriver>(database);

0 commit comments

Comments
 (0)