Package etch
Class 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
Fields inherited from class convex.core.store.ACachedStore
refCache
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <T extends ACell>
voidaddToCache
(Ref<T> ref) void
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 hash of the root data from the store.readStoreRef
(Hash hash) refForHash
(Hash hash) Gets the stored Ref for a given hash value, or null if not found in the store.setRootData
(T data) Sets the root data for this Storevoid
startGC()
Starts a GC cycle.Stores 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()
Methods inherited from class convex.core.store.ACachedStore
checkCache, decode
Methods inherited from class convex.core.store.AStore
decodeImpl, getRootData, getRootRef
-
Constructor Details
-
EtchStore
-
-
Method Details
-
startGC
Starts a GC cycle. Creates a new Etch file for collection, and directs all new writes to the new store- Throws:
IOException
- If an IO exception occurs
-
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
-
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 in the store. 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
-
readStoreRef
- Throws:
IOException
-
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
-
addToCache
-
toString
-
getFileName
Gets the database file name for this EtchStore- Returns:
- File name as a String
-
close
-
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 hash of the root data from the store. In order to set the root hash, go via setRootData.- Specified by:
getRootHash
in classAStore
- Returns:
- Root hash value from this store.
- Throws:
IOException
- In case of store IO error
-
setRootData
Description copied from class:AStore
Sets the root data for this Store- Specified by:
setRootData
in classAStore
- Parameters:
data
- Root data to set- Returns:
- Ref to written root data
- Throws:
IOException
- In case of store IO error
-
getEtch
-
shortName
-