Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 158 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ clonetree = "0.0.2"
criterion = "0.8.2"
derive_more = "2.1.1"
env_logger = "0.11.8"
fjall = { version = "3.1.9", default-features = false }
flume = { version = "0.12" }
futures = { version = "0.3.32", default-features = false }
heed = { version = "0.22.1", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion accountsdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ name = "accountsdb"
testkit = []

[dependencies]
nucleus = { workspace = true, features = ["heed", "metrics"] }
nucleus = { workspace = true, features = ["metrics"] }

ahash = { workspace = true }
bincode = { workspace = true }
Expand Down
3 changes: 1 addition & 2 deletions accountsdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ use std::{

use derive_more::From;
use nucleus::Slot;
use nucleus::heed::RoTxnTls;
use solana_account::{AccountSeqLock, AccountSharedData, CoWAccount};
use solana_pubkey::Pubkey;
use tracing::{info, warn};

use crate::{
store::{DatabaseVersion, PersistedProgramIter, PersistedStore},
store::{DatabaseVersion, PersistedProgramIter, PersistedStore, index::RoTxnTls},
volatile::VolatileStore,
};

Expand Down
42 changes: 34 additions & 8 deletions accountsdb/src/store/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use std::{fs, mem, path::Path};

use heed::{
Database, DatabaseFlags, Env, EnvFlags, EnvOpenOptions, IntegerComparator, Result, RoIter,
RoTxn, RwTxn, iteration_method::MoveOnCurrentKeyDuplicates,
RoTxn, RwTxn, WithTls, iteration_method::MoveOnCurrentKeyDuplicates,
};
use nucleus::heed::{DatabaseIndex, RoTxnTls};
use solana_pubkey::Pubkey;

use crate::store::kv::{KeyTail, Offset, OwnerAndOffset, PubkeyBytes, U32LE};
Expand All @@ -32,6 +31,29 @@ const FREELIST_INDEX: &str = "freelist";
type RoAccountIter<'a> = RoIter<'a, PubkeyBytes, OwnerAndOffset>;
/// Duplicate iterator over program-owned persisted accounts.
type RoProgramIter<'a> = RoIter<'a, KeyTail, Offset, MoveOnCurrentKeyDuplicates>;
/// Read-only transaction using heed thread-local storage.
pub(crate) type RoTxnTls<'e> = RoTxn<'e, WithTls>;
/// Optional write transaction used by batched updates.
pub(crate) type OptRwTxn<'t, 'e> = &'t mut Option<RwTxn<'e>>;
/// Optional read transaction used by batched reads.
pub(crate) type OptRoTxn<'t, 'e> = &'t mut Option<RoTxnTls<'e>>;

/// Uses the supplied write transaction or opens one against `env` on demand.
pub(crate) fn write_txn<'t, 'e>(env: &'e Env, txn: OptRwTxn<'t, 'e>) -> Result<&'t mut RwTxn<'e>> {
if let Some(txn) = txn {
return Ok(txn);
}
Ok(txn.insert(env.write_txn()?))
}

/// Uses the supplied read transaction or opens one against `env` on demand.
pub(crate) fn read_txn<'t, 'e>(env: &'e Env, txn: OptRoTxn<'t, 'e>) -> Result<&'t RoTxnTls<'e>> {
if let Some(txn) = txn {
return Ok(txn);
}
Ok(txn.insert(env.read_txn()?))
}

/// Iterator over persisted accounts.
pub(crate) struct AccountIter<'a> {
/// Iterator over `pubkey -> account` entries.
Expand Down Expand Up @@ -100,6 +122,16 @@ impl Index {
})
}

/// Returns the owning heed environment.
pub(crate) fn env(&self) -> &Env {
&self.env
}

/// Flushes the index databases to durable storage.
pub(crate) fn flush(&self) -> Result<()> {
self.env.force_sync()
}

/// Returns the persisted offset for `pubkey`.
pub(crate) fn offset(&self, key: &Pubkey, txn: &RoTxn<'_>) -> Result<Option<Offset>> {
let entry = self.accounts.get(txn, key)?;
Expand Down Expand Up @@ -199,9 +231,3 @@ impl Index {
self.programs.put(txn, &owner, &offset)
}
}

impl DatabaseIndex for Index {
fn env(&self) -> &Env {
&self.env
}
}
Loading
Loading