Create RocksDB databases under correct path.

We used to create them under .zenith/.zenith/<timelineid>. The double
.zenith was clearly not intentional. Change it to
.zenith/timelines/<timelineid>.

Fixes https://github.com/zenithdb/zenith/issues/127
This commit is contained in:
Heikki Linnakangas
2021-05-14 12:44:44 +03:00
parent 71e93faed7
commit c2db828481
2 changed files with 15 additions and 8 deletions

View File

@@ -7,6 +7,7 @@ use crate::PageServerConf;
//use crate::repository::Repository;
use crate::repository::rocksdb::RocksRepository;
use lazy_static::lazy_static;
use std::path::Path;
use std::sync::{Arc, Mutex};
lazy_static! {
@@ -16,7 +17,10 @@ lazy_static! {
pub fn init(conf: &PageServerConf) {
let mut m = REPOSITORY.lock().unwrap();
*m = Some(Arc::new(RocksRepository::new(conf)));
// we have already changed current dir to the repository.
let repo = RocksRepository::new(conf, Path::new("."));
*m = Some(Arc::new(repo));
}
pub fn get_repository() -> Arc<RocksRepository> {

View File

@@ -9,8 +9,8 @@ use crate::repository::{BufferTag, RelTag, Repository, Timeline, WALRecord};
use crate::restore_local_repo::restore_timeline;
use crate::waldecoder::{DecodedWALRecord, Oid, XlCreateDatabase, XlSmgrTruncate};
use crate::walredo::WalRedoManager;
use crate::PageServerConf;
use crate::ZTimelineId;
use crate::{zenith_repo_dir, PageServerConf};
use anyhow::{bail, Context, Result};
use bytes::{Buf, BufMut, Bytes, BytesMut};
use log::*;
@@ -18,6 +18,7 @@ use postgres_ffi::pg_constants;
use std::cmp::min;
use std::collections::HashMap;
use std::convert::TryInto;
use std::path::{Path, PathBuf};
use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering;
use std::sync::{Arc, Mutex};
@@ -30,6 +31,7 @@ use zenith_utils::seqwait::SeqWait;
static TIMEOUT: Duration = Duration::from_secs(60);
pub struct RocksRepository {
repo_dir: PathBuf,
conf: PageServerConf,
timelines: Mutex<HashMap<ZTimelineId, Arc<RocksTimeline>>>,
}
@@ -152,8 +154,9 @@ impl CacheEntryContent {
}
impl RocksRepository {
pub fn new(conf: &PageServerConf) -> RocksRepository {
pub fn new(conf: &PageServerConf, repo_dir: &Path) -> RocksRepository {
RocksRepository {
repo_dir: PathBuf::from(repo_dir),
conf: conf.clone(),
timelines: Mutex::new(HashMap::new()),
}
@@ -177,7 +180,7 @@ impl Repository for RocksRepository {
match timelines.get(&timelineid) {
Some(timeline) => Ok(timeline.clone()),
None => {
let timeline = RocksTimeline::new(&self.conf, timelineid);
let timeline = RocksTimeline::new(&self.conf, &self.repo_dir, timelineid);
restore_timeline(&self.conf, &timeline, timelineid)?;
@@ -203,8 +206,8 @@ impl Repository for RocksRepository {
}
impl RocksTimeline {
fn open_rocksdb(_conf: &PageServerConf, timelineid: ZTimelineId) -> rocksdb::DB {
let path = zenith_repo_dir().join(timelineid.to_string());
fn open_rocksdb(repo_dir: &Path, timelineid: ZTimelineId) -> rocksdb::DB {
let path = repo_dir.join("timelines").join(timelineid.to_string());
let mut opts = rocksdb::Options::default();
opts.create_if_missing(true);
opts.set_use_fsync(true);
@@ -219,9 +222,9 @@ impl RocksTimeline {
rocksdb::DB::open(&opts, &path).unwrap()
}
fn new(conf: &PageServerConf, timelineid: ZTimelineId) -> RocksTimeline {
fn new(conf: &PageServerConf, repo_dir: &Path, timelineid: ZTimelineId) -> RocksTimeline {
RocksTimeline {
db: RocksTimeline::open_rocksdb(&conf, timelineid),
db: RocksTimeline::open_rocksdb(repo_dir, timelineid),
walredo_mgr: WalRedoManager::new(conf, timelineid),