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.CommitQueuecommitQueueThe commit queue to coordinate the commits.static List<String>META_PROP_NAMESList of meta properties which are created by DocumentNodeStore and which needs to be retained in any cloned copy of DocumentNodeState.static StringSYS_PROP_DISABLE_JOURNALstatic StringSYS_PROP_DISABLE_SWEEP2static StringSYS_PROP_PREFETCHstatic FormatVersionVERSION-
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 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.booleancompare(@NotNull AbstractDocumentNodeState node, @NotNull AbstractDocumentNodeState base, @NotNull NodeStateDiff diff)@NotNull BlobStoreBlobcreateBlob(InputStream inputStream)Create aBlobfrom the given input stream.@Nullable MarkSweepGarbageCollectorcreateBlobGarbageCollector(long blobGcMaxAgeInSecs, String repositoryId, Whiteboard whiteboard, StatisticsProvider statisticsProvider)Creates and returns a MarkSweepGarbageCollector if the current BlobStore supports garbage collection@NotNull PropertyStatecreatePropertyState(String name, String value)voiddispose()intgetAsyncDelay()BlobgetBlob(@NotNull String reference)Returns theBlobwith the given reference.BlobgetBlobFromBlobId(String blobId)Returns theBlobwith the given blobId.BlobStoregetBlobStore()org.apache.jackrabbit.oak.plugins.document.UnmergedBranchesgetBranches()BundlingConfigHandlergetBundlingConfigHandler()intgetChangeSetMaxDepth()intgetChangeSetMaxItems()org.apache.jackrabbit.oak.plugins.document.CheckpointsgetCheckpoints()@NotNull ClockgetClock()intgetClusterId()@NotNull ClusterNodeInfogetClusterInfo()StringgetCommitValue(@NotNull Revision changeRevision, @NotNull NodeDocument doc)Retrieves the commit value for a given change.org.apache.jackrabbit.oak.plugins.document.DiffCachegetDiffCache()@NotNull Iterable<CacheStats>getDiffCacheStats()@NotNull DocumentStoregetDocumentStore()@NotNull RevisionVectorgetHeadRevision()StringgetInstanceId()Will return a unique number per instance across the cluster.@NotNull JournalGarbageCollectorgetJournalGarbageCollector()JournalPropertyHandlerFactorygetJournalPropertyHandlerFactory()@NotNull LastRevRecoveryAgentgetLastRevRecoveryAgent()intgetMaxBackOffMillis()longgetMaxTimeDiffMillis()DocumentNodeStoreMBeangetMBean()@Nullable DocumentNodeStategetNode(@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()CacheStatsgetNodeCacheStats()org.apache.jackrabbit.guava.common.cache.Cache<NamePathRev,DocumentNodeState.Children>getNodeChildrenCache()CacheStatsgetNodeChildrenCacheStats()DocumentNodeStateCachegetNodeStateCache()org.apache.jackrabbit.oak.plugins.document.UnsavedModificationsgetPendingModifications()intgetPendingWriteCount()org.apache.jackrabbit.guava.common.cache.Cache<StringValue,StringValue>getPrevNoPropCache()Iterator<ReferencedBlob>getReferencedBlobsIterator()Returns an iterator for all the blob present in the store.@NotNull DocumentNodeStategetRoot()Returns the latest state of the tree.DocumentNodeStoreStatsCollectorgetStatsCollector()@NotNull VersionGarbageCollectorgetVersionGarbageCollector()StringgetVisibilityToken()Returns the visibility token of the underlying NodeStore.booleanisChildOrderCleanupEnabled()booleanisDisableBranches()booleanisVisible(@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 NodeStatemerge(@NotNull NodeBuilder builder, @NotNull CommitHook commitHook, @NotNull CommitInfo info)@NotNull RevisionnewRevision()voidprefetch(Collection<String> paths, NodeState rootState)Make an attempt to prefetch node states for the given paths and hold them in a cache.@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.@Nullable NodeStateretrieve(@NotNull String checkpoint)Retrieves the root node from a previously created repository checkpoint.voidrunBackgroundOperations()Used for testing onlyvoidsetAsyncDelay(int delay)voidsetChangeSetMaxDepth(int changeSetMaxDepth)voidsetChangeSetMaxItems(int changeSetMaxItems)voidsetMaxBackOffMillis(int time)voidsetNodeStateCache(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()
-
getPrevNoPropCache
public org.apache.jackrabbit.guava.common.cache.Cache<StringValue,StringValue> getPrevNoPropCache()
-
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
nullif 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:
comparein interfaceNodeStateDiffer- Parameters:
node- the node to compare.base- the base node to compare against.diff- handler of node state differences- Returns:
trueif the full diff was performed, orfalseif it was aborted as requested by the handler (see theNodeStateDiffcontract for more details)
-
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 DocumentNodeState 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 BlobStoreBlob 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)
Returns theBlobwith 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:
getBlobin interfaceNodeStore- Parameters:
reference- the reference of the blob.- Returns:
- the blob.
- See Also:
Blob.getReference()
-
getBlobFromBlobId
public Blob getBlobFromBlobId(String blobId)
Returns theBlobwith 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: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
@Nullable public @Nullable NodeState retrieve(@NotNull @NotNull String checkpoint)
Description copied from interface:NodeStoreRetrieves the root node from a previously created repository checkpoint.
-
release
public boolean release(@NotNull @NotNull String checkpoint)Description copied from interface:NodeStoreReleases 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:
getBranchesin 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:
getPendingModificationsin interfaceRevisionContext- Returns:
- the pending modifications.
-
getClusterId
public int getClusterId()
- Specified by:
getClusterIdin interfaceRevisionContext- Returns:
- the cluster id of the local DocumentMK instance.
-
getHeadRevision
@NotNull public @NotNull RevisionVector getHeadRevision()
- Specified by:
getHeadRevisionin interfaceRevisionContext- Returns:
- the current head revision.
-
newRevision
@NotNull public @NotNull Revision newRevision()
- Specified by:
newRevisionin interfaceRevisionContext- Returns:
- a new revision for the local document node store instance.
-
getClock
@NotNull public @NotNull Clock getClock()
- Specified by:
getClockin 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:RevisionContextRetrieves 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:
getCommitValuein interfaceRevisionContext- Parameters:
changeRevision- the revision a change was made.doc- the document where the change was made.- Returns:
- the commit value or
nullif 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:ClusterableWill 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:
getInstanceIdin interfaceClusterable- Returns:
- Cannot be null or empty.
-
getVisibilityToken
public String getVisibilityToken()
Description copied from interface:ClusterableReturns 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:
getVisibilityTokenin interfaceClusterable
-
isVisible
public boolean isVisible(@NotNull @NotNull String visibilityToken, long maxWaitMillis) throws InterruptedExceptionDescription copied from interface:ClusterableChecks 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:
isVisiblein 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:PrefetchNodeStoreMake an attempt to prefetch node states for the given paths and hold them in a cache.- Specified by:
prefetchin interfacePrefetchNodeStore- Parameters:
paths- the paths of the node states to prefetch.rootState- the current root node state.
-
-