Package etch
Class EtchStore
java.lang.Object
convex.core.store.AStore
etch.EtchStore
Class implementing on-disk memory-mapped storage of Convex data.
"There are only two hard things in Computer Science: cache invalidation and
naming things." - Phil Karlton
Objects are keyed by cryptographic hash. That solves naming. Objects are
immutable. That solves cache invalidation.
Garbage collection is left as an exercise for the reader.
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this store and frees associated resourcesstatic EtchStore
Creates an EtchStore using a specified file.static EtchStore
Create an Etch store using a new temporary file with a generated prefixstatic EtchStore
createTemp(String prefix)
Create an Etch store using a new temporary file with the given prefixvoid
flush()
Ensure the store is fully persisted to diskgetEtch()
Gets the underlying Etch instancegetFile()
Gets the database file name for this EtchStoreGets the Root Hash from the Store.refForHash(Hash hash)
Gets the stored Ref for a given hash value, or null if not found.void
setRootHash(Hash h)
Sets the root hash for this StoreStores a @Ref in long term storage as defined by this store implementation.storeTopRef(Ref<T> ref, int status, Consumer<Ref<ACell>> noveltyHandler)
Stores a top level @Ref in long term storage as defined by this store implementation.toString()
-
Constructor Details
-
EtchStore
-
-
Method Details
-
create
Creates an EtchStore using a specified file.- Parameters:
file
- File to use for storage. Will be created it it does not already exist.- Returns:
- EtchStore instance
- Throws:
IOException
- If an IO error occurs
-
createTemp
Create an Etch store using a new temporary file with the given prefix- Parameters:
prefix
- String prefix for temporary file- Returns:
- New EtchStore instance
-
createTemp
Create an Etch store using a new temporary file with a generated prefix- Returns:
- New EtchStore instance
-
refForHash
Description copied from class:AStore
Gets the stored Ref for a given hash value, or null if not found. If the result is non-null, the Ref will have a status equal to STORED at minimum. Calls to Ref.getValue() should therefore never throw MissingDataException.- Specified by:
refForHash
in classAStore
- Parameters:
hash
- A hash value to look up in the persisted store- Returns:
- The stored Ref, or null if the hash value is not persisted
-
storeRef
public <T extends ACell> Ref<T> storeRef(Ref<T> ref, int status, Consumer<Ref<ACell>> noveltyHandler)Description copied from class:AStore
Stores a @Ref in long term storage as defined by this store implementation. Will store nested Refs if required. Does not store embedded values. If it is necessary to persist an embedded value deliberately in the store, use storeTopRef(...) instead. If the persisted Ref represents novelty (i.e. not previously stored) Will call the provided noveltyHandler.- Specified by:
storeRef
in classAStore
- Parameters:
ref
- A Ref to the given object. Should be either Direct or STORED at minimum to present risk of MissingDataException.status
- Status to store atnoveltyHandler
- Novelty Handler function for Novelty detected. May be null.- Returns:
- The persisted Ref, of status STORED at minimum
-
storeTopRef
public <T extends ACell> Ref<T> storeTopRef(Ref<T> ref, int status, Consumer<Ref<ACell>> noveltyHandler)Description copied from class:AStore
Stores a top level @Ref in long term storage as defined by this store implementation. Will store nested Refs if required. Will only store an embedded Ref if it is the top level item. If the persisted Ref represents novelty (i.e. not previously stored) Will call the provided noveltyHandler- Specified by:
storeTopRef
in classAStore
- Parameters:
ref
- A Ref to the given object. Should be either Direct or STORED at minimum to present risk of MissingDataException.status
- Status to store atnoveltyHandler
- Novelty Handler function for Novelty detected. May be null.- Returns:
- The persisted Ref, of status STORED at minimum
-
storeRef
-
toString
-
getFileName
Gets the database file name for this EtchStore- Returns:
- File name as a String
-
close
public void close()Description copied from class:AStore
Closes this store and frees associated resources -
flush
Ensure the store is fully persisted to disk- Throws:
IOException
- If an IO error occurs
-
getFile
-
getRootHash
Description copied from class:AStore
Gets the Root Hash from the Store. Root hash is typically used to store the Peer state in situations where the Peer needs to be restored from persistent storage.- Specified by:
getRootHash
in classAStore
- Returns:
- Root hash value from this store.
- Throws:
IOException
- In case of store IO error
-
setRootHash
Description copied from class:AStore
Sets the root hash for this Store- Specified by:
setRootHash
in classAStore
- Parameters:
h
- Root Hash to set- Throws:
IOException
- In case of store IO error
-
getEtch
Gets the underlying Etch instance- Returns:
- Etch instance
-