Class DocumentNodeStore
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore
-
- All Implemented Interfaces:
NodeStateDiffer
,RevisionContext
,Observable
,Clusterable
,NodeStore
,PrefetchNodeStore
public final class DocumentNodeStore extends Object implements NodeStore, RevisionContext, Observable, Clusterable, PrefetchNodeStore, NodeStateDiffer
Implementation of a NodeStore onDocumentStore
.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.jackrabbit.oak.plugins.document.CommitQueue
commitQueue
The commit queue to coordinate the commits.static List<String>
META_PROP_NAMES
List of meta properties which are created by DocumentNodeStore and which needs to be retained in any cloned copy of DocumentNodeState.static String
SYS_PROP_DISABLE_JOURNAL
static String
SYS_PROP_DISABLE_SWEEP2
static String
SYS_PROP_PREFETCH
static FormatVersion
VERSION
-
Fields inherited from interface org.apache.jackrabbit.oak.plugins.document.NodeStateDiffer
DEFAULT_DIFFER
-
Fields inherited from interface org.apache.jackrabbit.oak.spi.state.PrefetchNodeStore
NOOP
-
-
Constructor Summary
Constructors Constructor Description DocumentNodeStore(DocumentNodeStoreBuilder<?> builder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Closeable
addObserver(Observer observer)
Register a newObserver
.@NotNull String
checkpoint(long lifetime)
Creates a new checkpoint of the latest root of the tree.@NotNull String
checkpoint(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.boolean
compare(@NotNull AbstractDocumentNodeState node, @NotNull AbstractDocumentNodeState base, @NotNull NodeStateDiff diff)
@NotNull BlobStoreBlob
createBlob(InputStream inputStream)
Create aBlob
from the given input stream.@Nullable MarkSweepGarbageCollector
createBlobGarbageCollector(long blobGcMaxAgeInSecs, String repositoryId, Whiteboard whiteboard, StatisticsProvider statisticsProvider)
Creates and returns a MarkSweepGarbageCollector if the current BlobStore supports garbage collection@NotNull PropertyState
createPropertyState(String name, String value)
void
dispose()
int
getAsyncDelay()
Blob
getBlob(@NotNull String reference)
Returns theBlob
with the given reference.Blob
getBlobFromBlobId(String blobId)
Returns theBlob
with the given blobId.BlobStore
getBlobStore()
org.apache.jackrabbit.oak.plugins.document.UnmergedBranches
getBranches()
BundlingConfigHandler
getBundlingConfigHandler()
int
getChangeSetMaxDepth()
int
getChangeSetMaxItems()
org.apache.jackrabbit.oak.plugins.document.Checkpoints
getCheckpoints()
@NotNull Clock
getClock()
int
getClusterId()
@NotNull ClusterNodeInfo
getClusterInfo()
String
getCommitValue(@NotNull Revision changeRevision, @NotNull NodeDocument doc)
Retrieves the commit value for a given change.org.apache.jackrabbit.oak.plugins.document.DiffCache
getDiffCache()
@NotNull Iterable<CacheStats>
getDiffCacheStats()
@NotNull DocumentStore
getDocumentStore()
@NotNull RevisionVector
getHeadRevision()
String
getInstanceId()
Will return a unique number per instance across the cluster.@NotNull JournalGarbageCollector
getJournalGarbageCollector()
JournalPropertyHandlerFactory
getJournalPropertyHandlerFactory()
@NotNull LastRevRecoveryAgent
getLastRevRecoveryAgent()
int
getMaxBackOffMillis()
long
getMaxTimeDiffMillis()
DocumentNodeStoreMBean
getMBean()
@Nullable DocumentNodeState
getNode(@NotNull Path path, @NotNull RevisionVector rev)
Get the node for the given path and revision.org.apache.jackrabbit.guava.common.cache.Cache<PathRev,DocumentNodeState>
getNodeCache()
Predicate<Path>
getNodeCachePredicate()
CacheStats
getNodeCacheStats()
org.apache.jackrabbit.guava.common.cache.Cache<NamePathRev,DocumentNodeState.Children>
getNodeChildrenCache()
CacheStats
getNodeChildrenCacheStats()
DocumentNodeStateCache
getNodeStateCache()
org.apache.jackrabbit.oak.plugins.document.UnsavedModifications
getPendingModifications()
int
getPendingWriteCount()
Iterator<ReferencedBlob>
getReferencedBlobsIterator()
Returns an iterator for all the blob present in the store.@NotNull DocumentNodeState
getRoot()
Returns the latest state of the tree.DocumentNodeStoreStatsCollector
getStatsCollector()
@NotNull VersionGarbageCollector
getVersionGarbageCollector()
String
getVisibilityToken()
Returns the visibility token of the underlying NodeStore.boolean
isChildOrderCleanupEnabled()
boolean
isDisableBranches()
boolean
isVisible(@NotNull String visibilityToken, long maxWaitMillis)
Checks if the underlying NodeStore sees at least the changes that were visible at the time the visibility token was created on potentially another instance if in a clustered NodeStore setup.@NotNull NodeState
merge(@NotNull NodeBuilder builder, @NotNull CommitHook commitHook, @NotNull CommitInfo info)
@NotNull Revision
newRevision()
void
prefetch(Collection<String> paths, NodeState rootState)
Make an attempt to prefetch node states for the given paths and hold them in a cache.@NotNull NodeState
rebase(@NotNull NodeBuilder builder)
boolean
release(@NotNull String checkpoint)
Releases the provided checkpoint.NodeState
reset(@NotNull NodeBuilder builder)
Reset the passedbuilder
by throwing away all its changes and setting its base state to the current root state.@Nullable NodeState
retrieve(@NotNull String checkpoint)
Retrieves the root node from a previously created repository checkpoint.void
runBackgroundOperations()
Used for testing onlyvoid
setAsyncDelay(int delay)
void
setChangeSetMaxDepth(int changeSetMaxDepth)
void
setChangeSetMaxItems(int changeSetMaxItems)
void
setMaxBackOffMillis(int time)
void
setNodeStateCache(DocumentNodeStateCache nodeStateCache)
-
-
-
Field Detail
-
VERSION
public static final FormatVersion VERSION
-
META_PROP_NAMES
public static final List<String> META_PROP_NAMES
List of meta properties which are created by DocumentNodeStore and which needs to be retained in any cloned copy of DocumentNodeState.
-
SYS_PROP_DISABLE_JOURNAL
public static final String SYS_PROP_DISABLE_JOURNAL
- See Also:
- Constant Field Values
-
SYS_PROP_DISABLE_SWEEP2
public static final String SYS_PROP_DISABLE_SWEEP2
- See Also:
- Constant Field Values
-
SYS_PROP_PREFETCH
public static final String SYS_PROP_PREFETCH
- See Also:
- Constant Field Values
-
commitQueue
protected final org.apache.jackrabbit.oak.plugins.document.CommitQueue commitQueue
The commit queue to coordinate the commits.
-
-
Constructor Detail
-
DocumentNodeStore
public DocumentNodeStore(DocumentNodeStoreBuilder<?> builder)
-
-
Method Detail
-
isChildOrderCleanupEnabled
public boolean isChildOrderCleanupEnabled()
-
dispose
public void dispose()
-
getDocumentStore
@NotNull public @NotNull DocumentStore getDocumentStore()
-
setAsyncDelay
public void setAsyncDelay(int delay)
-
getAsyncDelay
public int getAsyncDelay()
-
setMaxBackOffMillis
public void setMaxBackOffMillis(int time)
-
getMaxBackOffMillis
public int getMaxBackOffMillis()
-
getChangeSetMaxItems
public int getChangeSetMaxItems()
-
setChangeSetMaxItems
public void setChangeSetMaxItems(int changeSetMaxItems)
-
getChangeSetMaxDepth
public int getChangeSetMaxDepth()
-
setChangeSetMaxDepth
public void setChangeSetMaxDepth(int changeSetMaxDepth)
-
getClusterInfo
@NotNull public @NotNull ClusterNodeInfo getClusterInfo()
-
getNodeCacheStats
public CacheStats getNodeCacheStats()
-
getNodeChildrenCacheStats
public CacheStats getNodeChildrenCacheStats()
-
getDiffCacheStats
@NotNull public @NotNull Iterable<CacheStats> getDiffCacheStats()
-
getNodeCache
public org.apache.jackrabbit.guava.common.cache.Cache<PathRev,DocumentNodeState> getNodeCache()
-
getNodeChildrenCache
public org.apache.jackrabbit.guava.common.cache.Cache<NamePathRev,DocumentNodeState.Children> getNodeChildrenCache()
-
getPendingWriteCount
public int getPendingWriteCount()
-
isDisableBranches
public boolean isDisableBranches()
-
getMaxTimeDiffMillis
public long getMaxTimeDiffMillis()
-
createPropertyState
@NotNull public @NotNull PropertyState createPropertyState(String name, String value)
-
getNode
@Nullable public @Nullable DocumentNodeState getNode(@NotNull @NotNull Path path, @NotNull @NotNull RevisionVector rev)
Get the node for the given path and revision. The returned object might not be modified directly.- Parameters:
path
- the path of the node.rev
- the read revision.- Returns:
- the node or
null
if the node does not exist at the given revision.
-
getBundlingConfigHandler
public BundlingConfigHandler getBundlingConfigHandler()
-
compare
public boolean compare(@NotNull @NotNull AbstractDocumentNodeState node, @NotNull @NotNull AbstractDocumentNodeState base, @NotNull @NotNull NodeStateDiff diff)
- Specified by:
compare
in interfaceNodeStateDiffer
- Parameters:
node
- the node to compare.base
- the base node to compare against.diff
- handler of node state differences- Returns:
true
if the full diff was performed, orfalse
if it was aborted as requested by the handler (see theNodeStateDiff
contract for more details)
-
addObserver
public Closeable addObserver(Observer observer)
Description copied from interface:Observable
Register 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:
addObserver
in interfaceObservable
- Returns:
- a
Closeable
instance.
-
getRoot
@NotNull public @NotNull DocumentNodeState getRoot()
Description copied from interface:NodeStore
Returns 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:
merge
in 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:NodeStore
Reset the passedbuilder
by throwing away all its changes and setting its base state to the current root state.
-
createBlob
@NotNull public @NotNull BlobStoreBlob createBlob(InputStream inputStream) throws IOException
Description copied from interface:NodeStore
Create aBlob
from the given input stream. The input stream is closed after this method returns.- Specified by:
createBlob
in interfaceNodeStore
- Parameters:
inputStream
- The input stream for theBlob
- Returns:
- The
Blob
representinginputStream
- Throws:
IOException
- If an error occurs while reading from the stream
-
getBlob
public Blob getBlob(@NotNull @NotNull String reference)
Returns theBlob
with the given reference. Note that this method is meant to be used with secure reference obtained from Blob#reference which is different from blobId- Specified by:
getBlob
in interfaceNodeStore
- Parameters:
reference
- the reference of the blob.- Returns:
- the blob.
- See Also:
Blob.getReference()
-
getBlobFromBlobId
public Blob getBlobFromBlobId(String blobId)
Returns theBlob
with the given blobId.- Parameters:
blobId
- the blobId of the blob.- Returns:
- the blob.
-
checkpoint
@NotNull public @NotNull String checkpoint(long lifetime, @NotNull @NotNull Map<String,String> properties)
Description copied from interface:NodeStore
Creates 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
properties
passed 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:
checkpoint
in 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:NodeStore
Creates 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:
checkpoint
in 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:NodeStore
Retrieve the properties associated with a checkpoint.- Specified by:
checkpointInfo
in interfaceNodeStore
- Parameters:
checkpoint
- string reference of a checkpoint- Returns:
- the properties associated with the checkpoint referenced by
checkpoint
or an empty map when there is no such checkpoint.
-
checkpoints
@NotNull public @NotNull Iterable<String> checkpoints()
Description copied from interface:NodeStore
Returns all valid checkpoints. The returnedIterable
provides a snapshot of valid checkpoints at the time this method is called. That is, theIterable
will not reflect checkpoints created after this method was called.See
NodeStore.checkpoint(long, Map)
for a definition of a valid checkpoint.- Specified by:
checkpoints
in interfaceNodeStore
- Returns:
- valid checkpoints.
-
retrieve
@Nullable public @Nullable NodeState retrieve(@NotNull @NotNull String checkpoint)
Description copied from interface:NodeStore
Retrieves the root node from a previously created repository checkpoint.
-
release
public boolean release(@NotNull @NotNull String checkpoint)
Description copied from interface:NodeStore
Releases the provided checkpoint. If the provided checkpoint doesn't exist this method should returntrue
.
-
getBranches
public org.apache.jackrabbit.oak.plugins.document.UnmergedBranches getBranches()
- Specified by:
getBranches
in interfaceRevisionContext
- Returns:
- the branches of the local DocumentMK instance, which are not yet merged.
-
getPendingModifications
public org.apache.jackrabbit.oak.plugins.document.UnsavedModifications getPendingModifications()
- Specified by:
getPendingModifications
in interfaceRevisionContext
- Returns:
- the pending modifications.
-
getClusterId
public int getClusterId()
- Specified by:
getClusterId
in interfaceRevisionContext
- Returns:
- the cluster id of the local DocumentMK instance.
-
getHeadRevision
@NotNull public @NotNull RevisionVector getHeadRevision()
- Specified by:
getHeadRevision
in interfaceRevisionContext
- Returns:
- the current head revision.
-
newRevision
@NotNull public @NotNull Revision newRevision()
- Specified by:
newRevision
in interfaceRevisionContext
- Returns:
- a new revision for the local document node store instance.
-
getClock
@NotNull public @NotNull Clock getClock()
- Specified by:
getClock
in interfaceRevisionContext
- Returns:
- the clock in use when a new revision is created.
-
getCommitValue
public String getCommitValue(@NotNull @NotNull Revision changeRevision, @NotNull @NotNull NodeDocument doc)
Description copied from interface:RevisionContext
Retrieves the commit value for a given change. This method returns the following types of commit values:- "c" : the change revision is committed as is.
- "c-rX-Y-Z" : the change revision is a branch commit merged in revision "rX-Y-Z".
- "brX-Y-Z" : the change revision is a branch commit done at "rX-Y-Z" but not yet merged.
null
: the change revision does not have an entry on the commit root document and is not committed.
- Specified by:
getCommitValue
in interfaceRevisionContext
- Parameters:
changeRevision
- the revision a change was made.doc
- the document where the change was made.- Returns:
- the commit value or
null
if the change does not have a commit value (yet).
-
runBackgroundOperations
public void runBackgroundOperations()
Used for testing only
-
createBlobGarbageCollector
@Nullable public @Nullable MarkSweepGarbageCollector createBlobGarbageCollector(long blobGcMaxAgeInSecs, String repositoryId, Whiteboard whiteboard, StatisticsProvider statisticsProvider)
Creates and returns a MarkSweepGarbageCollector if the current BlobStore supports garbage collection- Parameters:
blobGcMaxAgeInSecs
-repositoryId
-whiteboard
-statisticsProvider
-- Returns:
- garbage collector of the BlobStore supports GC otherwise null
-
getMBean
public DocumentNodeStoreMBean getMBean()
-
getBlobStore
public BlobStore getBlobStore()
-
getReferencedBlobsIterator
public Iterator<ReferencedBlob> getReferencedBlobsIterator()
Returns an iterator for all the blob present in the store.In some cases the iterator might implement
Closeable
. So callers should check for such iterator and close them.- Returns:
- an iterator for all the blobs
-
getDiffCache
public org.apache.jackrabbit.oak.plugins.document.DiffCache getDiffCache()
-
getCheckpoints
public org.apache.jackrabbit.oak.plugins.document.Checkpoints getCheckpoints()
-
getVersionGarbageCollector
@NotNull public @NotNull VersionGarbageCollector getVersionGarbageCollector()
-
getJournalGarbageCollector
@NotNull public @NotNull JournalGarbageCollector getJournalGarbageCollector()
-
getLastRevRecoveryAgent
@NotNull public @NotNull LastRevRecoveryAgent getLastRevRecoveryAgent()
-
getInstanceId
public String getInstanceId()
Description copied from interface:Clusterable
Will return a unique number per instance across the cluster. It will only make its best effort to preserve the same number across restarts but it must be unique across the cluster.
- Specified by:
getInstanceId
in interfaceClusterable
- Returns:
- Cannot be null or empty.
-
getVisibilityToken
public String getVisibilityToken()
Description copied from interface:Clusterable
Returns the visibility token of the underlying NodeStore. A 'visibility token' is an opaque String that can be used to verify if changes done on one NodeStore are visible on another NodeStore of the same cluster. This can be achieved by generating such a visibility token on the source NodeStore, passing it on to the target NodeStore (by whatever means) and checking for visibility on that target NodeStore.
The visibility check returns true if the target NodeStore sees at least all the changes that the source NodeStore saw at time of visibility token generation. Once a visibility token is visible on a particular NodeStore it will always return true ever after. This also implies that the visibility check can only state whether at least all source changes are visible on the target and that it is independent of any further modifications.
When source and target NodeStore are identical, the visibility check is expected to return true, immediately. This is based on the assumption that with a session.refresh() on that NodeStore you'll always get the latest changes applied by any other session locally.
Visibility tokens are meant to be lightweight and are not expected to be persisted by the implementor. Nevertheless they should survive their validity in the case of crashes of the source and/or the target instance.
- Specified by:
getVisibilityToken
in interfaceClusterable
-
isVisible
public boolean isVisible(@NotNull @NotNull String visibilityToken, long maxWaitMillis) throws InterruptedException
Description copied from interface:Clusterable
Checks if the underlying NodeStore sees at least the changes that were visible at the time the visibility token was created on potentially another instance if in a clustered NodeStore setup.
If the visibility token was created on the underlying NodeStore this check always returns true, immediately.
- Specified by:
isVisible
in interfaceClusterable
- Parameters:
visibilityToken
- the visibility token that was created on another instance in a clustered NodeStore setup. Providing null is not supported and might throw a RuntimeExceptionmaxWaitMillis
- if >-1 waits (at max this many milliseconds if >0, forever if ==0) until the underlying NodeStore sees at least the changes represented by the provided visibility token. if < 0 the method does not wait- Returns:
- true if the underlying NodeStore sees at least the changes that were visible at the time the visibility token was created
- Throws:
InterruptedException
- (optionally) thrown if interrupted while waiting
-
getStatsCollector
public DocumentNodeStoreStatsCollector getStatsCollector()
-
getNodeStateCache
public DocumentNodeStateCache getNodeStateCache()
-
setNodeStateCache
public void setNodeStateCache(DocumentNodeStateCache nodeStateCache)
-
getJournalPropertyHandlerFactory
public JournalPropertyHandlerFactory getJournalPropertyHandlerFactory()
-
prefetch
public void prefetch(Collection<String> paths, NodeState rootState)
Description copied from interface:PrefetchNodeStore
Make an attempt to prefetch node states for the given paths and hold them in a cache.- Specified by:
prefetch
in interfacePrefetchNodeStore
- Parameters:
paths
- the paths of the node states to prefetch.rootState
- the current root node state.
-
-