Skip to content

Commit

Permalink
Add ReplicaStore (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind authored Mar 9, 2022
1 parent c4f8f2d commit 2f50ab5
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions sui_core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@ use typed_store::rocks::{open_cf, DBBatch, DBMap};
use std::sync::atomic::Ordering;
use typed_store::traits::Map;

pub struct AuthorityStore {
pub type AuthorityStore = SuiDataStore<true>;
#[allow(dead_code)]
pub type ReplicaStore = SuiDataStore<false>;

/// ALL_OBJ_VER determines whether we want to store all past
/// versions of every object in the store. Authority doesn't store
/// them, but other entities such as replicas will.
pub struct SuiDataStore<const ALL_OBJ_VER: bool> {
/// This is a map between the object ID and the latest state of the object, namely the
/// state that is needed to process new transactions. If an object is deleted its entry is
/// removed from this map.
objects: DBMap<ObjectID, Object>,

/// Stores all history versions of all objects.
/// This is not needed by an authority, but is needed by a replica.
#[allow(dead_code)]
all_object_versions: DBMap<(ObjectID, SequenceNumber), Object>,

/// This is a map between object references of currently active objects that can be mutated,
/// and the transaction that they are lock on for use by this specific authority. Where an object
/// lock exists for an object version, but no transaction has been seen using it the lock is set
Expand Down Expand Up @@ -81,14 +93,15 @@ pub struct AuthorityStore {
pub next_sequence_number: AtomicU64,
}

impl AuthorityStore {
impl<const ALL_OBJ_VER: bool> SuiDataStore<ALL_OBJ_VER> {
/// Open an authority store by directory path
pub fn open<P: AsRef<Path>>(path: P, db_options: Option<Options>) -> AuthorityStore {
let db = open_cf(
&path,
db_options,
&[
"objects",
"all_object_versions",
"owner_index",
"transaction_lock",
"signed_transactions",
Expand Down Expand Up @@ -120,6 +133,8 @@ impl AuthorityStore {

AuthorityStore {
objects: DBMap::reopen(&db, Some("objects")).expect("Cannot open CF."),
all_object_versions: DBMap::reopen(&db, Some("all_object_versions"))
.expect("Cannot open CF."),
owner_index: DBMap::reopen(&db, Some("owner_index")).expect("Cannot open CF."),
transaction_lock: DBMap::reopen(&db, Some("transaction_lock"))
.expect("Cannot open CF."),
Expand Down Expand Up @@ -503,6 +518,16 @@ impl AuthorityStore {
}),
)?;

if ALL_OBJ_VER {
// Keep all versions of every object if ALL_OBJ_VER is true.
write_batch = write_batch.insert_batch(
&self.all_object_versions,
written
.iter()
.map(|(id, object)| ((*id, object.version()), object)),
)?;
}

// Update the indexes of the objects written
write_batch = write_batch.insert_batch(
&self.owner_index,
Expand Down

1 comment on commit 2f50ab5

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bench results

�[0m�[0m�[1m�[32m Finished�[0m release [optimized] target(s) in 0.33s
�[0m�[0m�[1m�[32m Running�[0m target/release/bench
�[2m2022-03-09T04:20:34.253928Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Starting benchmark: TransactionsAndCerts
�[2m2022-03-09T04:20:34.253965Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Preparing accounts.
�[2m2022-03-09T04:20:34.254418Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Open database on path: "/tmp/DB_5E10C083A612AD894D34BDA5B7ABBA6A75512B65"
�[2m2022-03-09T04:20:39.392712Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Preparing transactions.
�[2m2022-03-09T04:20:48.520806Z�[0m �[32m INFO�[0m �[2msui_network::transport�[0m�[2m:�[0m Listening to TCP traffic on 127.0.0.1:9555
�[2m2022-03-09T04:20:49.522539Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Number of TCP connections: 2
�[2m2022-03-09T04:20:49.522568Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Set max_in_flight to 500
�[2m2022-03-09T04:20:49.522571Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Sending requests.
�[2m2022-03-09T04:20:49.527541Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Sending TCP requests to 127.0.0.1:9555
�[2m2022-03-09T04:20:49.532069Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Sending TCP requests to 127.0.0.1:9555
�[2m2022-03-09T04:20:50.535030Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 5000 packets
�[2m2022-03-09T04:20:51.383861Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 35000
�[2m2022-03-09T04:20:51.461155Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 35000
�[2m2022-03-09T04:20:51.513670Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 10000 packets
�[2m2022-03-09T04:20:52.493107Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 15000 packets
�[2m2022-03-09T04:20:53.347234Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 30000
�[2m2022-03-09T04:20:53.440680Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 30000
�[2m2022-03-09T04:20:53.450491Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 20000 packets
�[2m2022-03-09T04:20:54.405096Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 25000 packets
�[2m2022-03-09T04:20:55.239507Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 25000
�[2m2022-03-09T04:20:55.335807Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 25000
�[2m2022-03-09T04:20:55.365479Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 30000 packets
�[2m2022-03-09T04:20:56.334799Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 35000 packets
�[2m2022-03-09T04:20:57.179444Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 20000
�[2m2022-03-09T04:20:57.269299Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 20000
�[2m2022-03-09T04:20:57.326335Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 40000 packets
�[2m2022-03-09T04:20:58.324726Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 45000 packets
�[2m2022-03-09T04:20:59.212662Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 15000
�[2m2022-03-09T04:20:59.303445Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 15000
�[2m2022-03-09T04:20:59.325576Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 50000 packets
�[2m2022-03-09T04:21:00.322411Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 55000 packets
�[2m2022-03-09T04:21:01.180859Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 10000
�[2m2022-03-09T04:21:01.275594Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 10000
�[2m2022-03-09T04:21:01.316521Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 60000 packets
�[2m2022-03-09T04:21:02.310736Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 65000 packets
�[2m2022-03-09T04:21:03.164252Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 5000
�[2m2022-03-09T04:21:03.244508Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m In flight 500 Remaining 5000
�[2m2022-03-09T04:21:03.316500Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 70000 packets
�[2m2022-03-09T04:21:04.314384Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 75000 packets
�[2m2022-03-09T04:21:05.311343Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Done sending TCP requests to 127.0.0.1:9555
�[2m2022-03-09T04:21:05.353568Z�[0m �[32m INFO�[0m �[2msui_core::authority_server�[0m�[2m:�[0m 127.0.0.1:9555 has processed 80000 packets
�[2m2022-03-09T04:21:05.398756Z�[0m �[32m INFO�[0m �[2msui_network::network�[0m�[2m:�[0m Done sending TCP requests to 127.0.0.1:9555
�[2m2022-03-09T04:21:05.400509Z�[0m �[32m INFO�[0m �[2mbench�[0m�[2m:�[0m Received 80000 responses.
�[2m2022-03-09T04:21:05.617625Z�[0m �[33m WARN�[0m �[2mbench�[0m�[2m:�[0m Completed benchmark for TransactionsAndCerts
Total time: 15877927us, items: 40000, tx/sec: 2519.2205506424107

Please sign in to comment.