update storage len
This commit is contained in:
parent
8b41a5d725
commit
44967abd1c
11
net/net.sh
11
net/net.sh
|
@ -120,7 +120,7 @@ while [[ -n $1 ]]; do
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
while getopts "h?T:t:o:f:rD:c:Fn:x:s:" opt "${shortArgs[@]}"; do
|
while getopts "h?T:t:o:f:rD:c:Fn:i:x:s:" opt "${shortArgs[@]}"; do
|
||||||
case $opt in
|
case $opt in
|
||||||
h | \?)
|
h | \?)
|
||||||
usage
|
usage
|
||||||
|
@ -205,6 +205,9 @@ while getopts "h?T:t:o:f:rD:c:Fn:x:s:" opt "${shortArgs[@]}"; do
|
||||||
s)
|
s)
|
||||||
stakeNodesInGenesisBlock=$OPTARG
|
stakeNodesInGenesisBlock=$OPTARG
|
||||||
;;
|
;;
|
||||||
|
i)
|
||||||
|
nodeAddress=$OPTARG
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
usage "Error: unhandled option: $opt"
|
usage "Error: unhandled option: $opt"
|
||||||
;;
|
;;
|
||||||
|
@ -684,6 +687,12 @@ sanity)
|
||||||
stop)
|
stop)
|
||||||
stop
|
stop
|
||||||
;;
|
;;
|
||||||
|
stopnode)
|
||||||
|
stopNode "$nodeAddress" true
|
||||||
|
;;
|
||||||
|
startnode)
|
||||||
|
startNode "$nodeAddress" validator
|
||||||
|
;;
|
||||||
logs)
|
logs)
|
||||||
fetchRemoteLog() {
|
fetchRemoteLog() {
|
||||||
declare ipAddress=$1
|
declare ipAddress=$1
|
||||||
|
|
|
@ -113,7 +113,11 @@ impl Serialize for AccountStorage {
|
||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
let mut map = serializer.serialize_map(Some(self.0.len()))?;
|
let mut len: usize = 0;
|
||||||
|
for storage in self.0.values() {
|
||||||
|
len += storage.len();
|
||||||
|
}
|
||||||
|
let mut map = serializer.serialize_map(Some(len))?;
|
||||||
for fork_storage in self.0.values() {
|
for fork_storage in self.0.values() {
|
||||||
for (storage_id, account_storage_entry) in fork_storage {
|
for (storage_id, account_storage_entry) in fork_storage {
|
||||||
map.serialize_entry(storage_id, &**account_storage_entry)?;
|
map.serialize_entry(storage_id, &**account_storage_entry)?;
|
||||||
|
@ -323,7 +327,7 @@ impl AccountsDB {
|
||||||
.map_err(|_| AccountsDB::get_io_error("accounts index deserialize error"))?;
|
.map_err(|_| AccountsDB::get_io_error("accounts index deserialize error"))?;
|
||||||
let storage: AccountStorage = deserialize_from(&mut stream)
|
let storage: AccountStorage = deserialize_from(&mut stream)
|
||||||
.map_err(|_| AccountsDB::get_io_error("storage deserialize error"))?;
|
.map_err(|_| AccountsDB::get_io_error("storage deserialize error"))?;
|
||||||
let version: usize = deserialize_from(&mut stream)
|
let version: u64 = deserialize_from(&mut stream)
|
||||||
.map_err(|_| AccountsDB::get_io_error("write version deserialize error"))?;
|
.map_err(|_| AccountsDB::get_io_error("write version deserialize error"))?;
|
||||||
|
|
||||||
let mut ids: Vec<usize> = storage
|
let mut ids: Vec<usize> = storage
|
||||||
|
@ -336,7 +340,6 @@ impl AccountsDB {
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut index = self.accounts_index.write().unwrap();
|
let mut index = self.accounts_index.write().unwrap();
|
||||||
index.account_maps.extend(accounts_index.account_maps);
|
|
||||||
let union = index.roots.union(&accounts_index.roots);
|
let union = index.roots.union(&accounts_index.roots);
|
||||||
index.roots = union.cloned().collect();
|
index.roots = union.cloned().collect();
|
||||||
index.last_root = accounts_index.last_root;
|
index.last_root = accounts_index.last_root;
|
||||||
|
@ -345,7 +348,8 @@ impl AccountsDB {
|
||||||
}
|
}
|
||||||
self.next_id
|
self.next_id
|
||||||
.store(ids[ids.len() - 1] + 1, Ordering::Relaxed);
|
.store(ids[ids.len() - 1] + 1, Ordering::Relaxed);
|
||||||
self.write_version.store(version, Ordering::Relaxed);
|
self.write_version
|
||||||
|
.fetch_add(version as usize, Ordering::Relaxed);
|
||||||
self.generate_index();
|
self.generate_index();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -662,18 +666,17 @@ impl Serialize for AccountsDB {
|
||||||
S: serde::ser::Serializer,
|
S: serde::ser::Serializer,
|
||||||
{
|
{
|
||||||
use serde::ser::Error;
|
use serde::ser::Error;
|
||||||
let len = serialized_size(&self.accounts_index).unwrap()
|
let accounts_index = self.accounts_index.read().unwrap();
|
||||||
+ serialized_size(&self.storage).unwrap()
|
let storage = self.storage.read().unwrap();
|
||||||
+ std::mem::size_of::<usize>() as u64;
|
let len = serialized_size(&*accounts_index).unwrap()
|
||||||
|
+ serialized_size(&*storage).unwrap()
|
||||||
|
+ std::mem::size_of::<u64>() as u64;
|
||||||
let mut buf = vec![0u8; len as usize];
|
let mut buf = vec![0u8; len as usize];
|
||||||
let mut wr = Cursor::new(&mut buf[..]);
|
let mut wr = Cursor::new(&mut buf[..]);
|
||||||
serialize_into(&mut wr, &self.accounts_index).map_err(Error::custom)?;
|
let version: u64 = self.write_version.load(Ordering::Relaxed) as u64;
|
||||||
serialize_into(&mut wr, &self.storage).map_err(Error::custom)?;
|
serialize_into(&mut wr, &*accounts_index).map_err(Error::custom)?;
|
||||||
serialize_into(
|
serialize_into(&mut wr, &*storage).map_err(Error::custom)?;
|
||||||
&mut wr,
|
serialize_into(&mut wr, &version).map_err(Error::custom)?;
|
||||||
&(self.write_version.load(Ordering::Relaxed) as u64),
|
|
||||||
)
|
|
||||||
.map_err(Error::custom)?;
|
|
||||||
let len = wr.position() as usize;
|
let len = wr.position() as usize;
|
||||||
serializer.serialize_bytes(&wr.into_inner()[..len])
|
serializer.serialize_bytes(&wr.into_inner()[..len])
|
||||||
}
|
}
|
||||||
|
@ -1243,6 +1246,10 @@ mod tests {
|
||||||
let mut reader = BufReader::new(&buf[..]);
|
let mut reader = BufReader::new(&buf[..]);
|
||||||
let daccounts = AccountsDB::new(&paths.paths);
|
let daccounts = AccountsDB::new(&paths.paths);
|
||||||
assert!(daccounts.update_from_stream(&mut reader).is_ok());
|
assert!(daccounts.update_from_stream(&mut reader).is_ok());
|
||||||
|
assert_eq!(
|
||||||
|
daccounts.write_version.load(Ordering::Relaxed),
|
||||||
|
accounts.write_version.load(Ordering::Relaxed)
|
||||||
|
);
|
||||||
check_accounts(&daccounts, &pubkeys, 0, 100, 2);
|
check_accounts(&daccounts, &pubkeys, 0, 100, 2);
|
||||||
check_accounts(&daccounts, &pubkeys1, 1, 10, 1);
|
check_accounts(&daccounts, &pubkeys1, 1, 10, 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ pub struct AccountsIndex<T> {
|
||||||
pub roots: HashSet<Fork>,
|
pub roots: HashSet<Fork>,
|
||||||
|
|
||||||
//This value that needs to be stored to recover the index from AppendVec
|
//This value that needs to be stored to recover the index from AppendVec
|
||||||
|
#[serde(skip)]
|
||||||
pub last_root: Fork,
|
pub last_root: Fork,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue