Class COWNodeStore
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.cow.COWNodeStore
-
- All Implemented Interfaces:
Observable,NodeStore
public class COWNodeStore extends Object implements NodeStore, Observable
The copy-on-write (COW) node store implementation allows to temporarily switch the repository into the "testing" mode, in which all the changes are stored in a volatile storage, namely the MemoryNodeStore. After switching back to the "production" mode, the test changes should be dropped.
If the CoW is enabled, a special :cow=true property will be set on the root node returned by getRoot(). It's being used in the merge() to decide which store be modified. Removing this property will result in merging changes to the main node store, even in the CoW mode.
The checkpoint support is provided by the
BranchNodeStoreclass. All the existing checkpoints are still available in the CoW mode (until they expire). New checkpoints are only created in the MemoryNodeStore.Known limitations:
- turning the CoW mode on and off requires cleaning up the lucene indexing cache,
- switching the CoW mode may result in repository inconsistencies (eg. if two merges belongs to the same logical commit sequence),
- in the CoW mode the changes are stored in MemoryNodeStore, so it shouldn't be enabled for too long (otherwise it may exhaust the heap).
-
-
Constructor Summary
Constructors Constructor Description COWNodeStore(NodeStore store)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CloseableaddObserver(Observer observer)Register a newObserver.@NotNull Stringcheckpoint(long lifetime)Creates a new checkpoint of the latest root of the tree.@NotNull Stringcheckpoint(long lifetime, @NotNull Map<String,String> properties)Creates a new checkpoint of the latest root of the tree.@NotNull Map<String,String>checkpointInfo(@NotNull String checkpoint)Retrieve the properties associated with a checkpoint.@NotNull Iterable<String>checkpoints()Returns all valid checkpoints.@NotNull BlobcreateBlob(InputStream inputStream)Create aBlobfrom the given input stream.voiddisableCopyOnWrite()voidenableCopyOnWrite()BlobgetBlob(@NotNull String reference)Get a blob by its reference.@NotNull NodeStategetRoot()Returns the latest state of the tree.@NotNull NodeStatemerge(@NotNull NodeBuilder builder, @NotNull CommitHook commitHook, @NotNull CommitInfo info)@NotNull NodeStaterebase(@NotNull NodeBuilder builder)booleanrelease(@NotNull String checkpoint)Releases the provided checkpoint.NodeStatereset(@NotNull NodeBuilder builder)Reset the passedbuilderby throwing away all its changes and setting its base state to the current root state.NodeStateretrieve(@NotNull String checkpoint)Retrieves the root node from a previously created repository checkpoint.
-
-
-
Constructor Detail
-
COWNodeStore
public COWNodeStore(NodeStore store)
-
-
Method Detail
-
enableCopyOnWrite
public void enableCopyOnWrite() throws CommitFailedException- Throws:
CommitFailedException
-
disableCopyOnWrite
public void disableCopyOnWrite()
-
addObserver
public Closeable addObserver(Observer observer)
Description copied from interface:ObservableRegister a newObserver. Clients need to callCloseable.close()to stop getting notifications on the registered observer and to free up any resources associated with the registration.- Specified by:
addObserverin interfaceObservable- Returns:
- a
Closeableinstance.
-
getRoot
@NotNull public @NotNull NodeState getRoot()
Description copied from interface:NodeStoreReturns the latest state of the tree.
-
merge
@NotNull public @NotNull NodeState merge(@NotNull @NotNull NodeBuilder builder, @NotNull @NotNull CommitHook commitHook, @NotNull @NotNull CommitInfo info) throws CommitFailedException
Description copied from interface:NodeStore- Specified by:
mergein interfaceNodeStore- Parameters:
builder- the builder whose changes to applycommitHook- the commit hook to apply while merging changesinfo- commit info associated with this merge operation- Returns:
- the node state resulting from the merge.
- Throws:
CommitFailedException- if the merge failed
-
rebase
@NotNull public @NotNull NodeState rebase(@NotNull @NotNull NodeBuilder builder)
Description copied from interface:NodeStore
-
reset
public NodeState reset(@NotNull @NotNull NodeBuilder builder)
Description copied from interface:NodeStoreReset the passedbuilderby throwing away all its changes and setting its base state to the current root state.
-
createBlob
@NotNull public @NotNull Blob createBlob(InputStream inputStream) throws IOException
Description copied from interface:NodeStoreCreate aBlobfrom the given input stream. The input stream is closed after this method returns.- Specified by:
createBlobin interfaceNodeStore- Parameters:
inputStream- The input stream for theBlob- Returns:
- The
BlobrepresentinginputStream - Throws:
IOException- If an error occurs while reading from the stream
-
getBlob
public Blob getBlob(@NotNull @NotNull String reference)
Description copied from interface:NodeStoreGet a blob by its reference.- Specified by:
getBlobin interfaceNodeStore- Parameters:
reference- reference to the blob- Returns:
- blob or
nullif the reference does not resolve to a blob. - See Also:
Blob.getReference()
-
checkpoint
@NotNull public @NotNull String checkpoint(long lifetime, @NotNull @NotNull Map<String,String> properties)
Description copied from interface:NodeStoreCreates a new checkpoint of the latest root of the tree. The checkpoint remains valid for at least as long as requested and allows that state of the repository to be retrieved using the returned opaque string reference.The
propertiespassed to this methods are associated with the checkpoint and can be retrieved through theNodeStore.checkpointInfo(String)method. Its semantics is entirely application specific.- Specified by:
checkpointin interfaceNodeStore- Parameters:
lifetime- time (in milliseconds, > 0) that the checkpoint should remain availableproperties- properties to associate with the checkpoint- Returns:
- string reference of this checkpoint
-
checkpoint
@NotNull public @NotNull String checkpoint(long lifetime)
Description copied from interface:NodeStoreCreates a new checkpoint of the latest root of the tree. The checkpoint remains valid for at least as long as requested and allows that state of the repository to be retrieved using the returned opaque string reference.This method is a shortcut for
NodeStore.checkpoint(long, Map)passing an empty map for its 2nd argument.- Specified by:
checkpointin interfaceNodeStore- Parameters:
lifetime- time (in milliseconds, > 0) that the checkpoint should remain available- Returns:
- string reference of this checkpoint
-
checkpointInfo
@NotNull public @NotNull Map<String,String> checkpointInfo(@NotNull @NotNull String checkpoint)
Description copied from interface:NodeStoreRetrieve the properties associated with a checkpoint.- Specified by:
checkpointInfoin interfaceNodeStore- Parameters:
checkpoint- string reference of a checkpoint- Returns:
- the properties associated with the checkpoint referenced by
checkpointor an empty map when there is no such checkpoint.
-
checkpoints
@NotNull public @NotNull Iterable<String> checkpoints()
Description copied from interface:NodeStoreReturns all valid checkpoints. The returnedIterableprovides a snapshot of valid checkpoints at the time this method is called. That is, theIterablewill not reflect checkpoints created after this method was called.See
NodeStore.checkpoint(long, Map)for a definition of a valid checkpoint.- Specified by:
checkpointsin interfaceNodeStore- Returns:
- valid checkpoints.
-
retrieve
public NodeState retrieve(@NotNull @NotNull String checkpoint)
Description copied from interface:NodeStoreRetrieves the root node from a previously created repository checkpoint.
-
-