Skip to content

Commit

Permalink
fix: peer_store no such table error
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed Apr 8, 2019
1 parent b7bdd40 commit f75da93
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions network/src/peer_store/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ pub type ConnectionPool = Pool<SqliteConnectionManager>;
pub type PooledConnection = r2d2::PooledConnection<SqliteConnectionManager>;

lazy_static! {
static ref MEMORY_OPEN_FLAGS: OpenFlags = OpenFlags::SQLITE_OPEN_READ_WRITE
static ref OPEN_FLAGS: OpenFlags = OpenFlags::SQLITE_OPEN_READ_WRITE
| OpenFlags::SQLITE_OPEN_CREATE
| OpenFlags::SQLITE_OPEN_SHARED_CACHE
| OpenFlags::SQLITE_OPEN_NO_MUTEX;
static ref FILE_OPEN_FLAGS: OpenFlags = OpenFlags::SQLITE_OPEN_READ_WRITE
| OpenFlags::SQLITE_OPEN_CREATE
| OpenFlags::SQLITE_OPEN_NO_MUTEX;
}

pub enum StorePath {
Expand All @@ -54,11 +51,11 @@ pub fn open_pool(store_path: StorePath, max_size: u32) -> Result<ConnectionPool,
StorePath::Memory(db) => {
let manager =
SqliteConnectionManager::file(format!("file:{}?mode=memory&cache=shared", db));
manager.with_flags(*MEMORY_OPEN_FLAGS)
manager.with_flags(*OPEN_FLAGS)
}
StorePath::File(file_path) => {
let manager = SqliteConnectionManager::file(file_path);
manager.with_flags(*FILE_OPEN_FLAGS)
manager.with_flags(*OPEN_FLAGS)
}
};
Pool::builder()
Expand All @@ -71,11 +68,11 @@ pub fn open(store_path: StorePath) -> Result<Connection, DBError> {
match store_path {
StorePath::Memory(db) => Connection::open_with_flags(
format!("file:{}?mode=memory&cache=shared", db),
*MEMORY_OPEN_FLAGS,
*OPEN_FLAGS,
)
.map_err(Into::into),
StorePath::File(file_path) => {
Connection::open_with_flags(file_path, *FILE_OPEN_FLAGS).map_err(Into::into)
Connection::open_with_flags(file_path, *OPEN_FLAGS).map_err(Into::into)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion network/src/peer_store/sqlite/peer_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(crate) const LAST_CONNECTED_TIMEOUT_SECS: u64 = 14 * 24 * 3600;
/// Clear banned list if the list reach this size
const BAN_LIST_CLEAR_EXPIRES_SIZE: usize = 1024;
/// SQLITE connection pool size
const DEFAULT_POOL_SIZE: u32 = 16;
const DEFAULT_POOL_SIZE: u32 = 32;
const DEFAULT_ADDRS: u32 = 3;

pub struct SqlitePeerStore {
Expand Down

0 comments on commit f75da93

Please sign in to comment.