@Override public void notify( ChangeSet changeSet ) { if (changeSet == null || !getKey().equals(changeSet.getRepositoryKey())) { return; if (change instanceof WorkspaceAdded) { String addedName = ((WorkspaceAdded)change).getWorkspaceName(); if (!getWorkspaceNames().contains(addedName)) { changed = true; String removedName = ((WorkspaceRemoved)change).getWorkspaceName(); removedNames.add(removedName); if (getWorkspaceNames().contains(removedName)) { changed = true; refreshRepositoryMetadata(false); removeWorkspaceCaches(removedName);
final boolean checkPermissionsWhenIteratingChildren() { // we cannot "cache" the ACL enabled/disabled state because it's dynamic return this.hasCustomAuthorizationProvider || repository.repositoryCache().isAccessControlEnabled(); }
refreshRepositoryMetadata(true); ConcurrentMap<NodeKey, CachedNode> nodeCache = cacheForWorkspace().asMap(); ExecutionContext context = context(); throw new IllegalArgumentException(JcrI18n.connectorNotFound.text(sourceName)); FederatedDocumentStore documentStore = new FederatedDocumentStore(connectors, this.documentStore().localStore()); String rootId = connector.getRootDocumentId(); WorkspaceCache workspaceCache = new WorkspaceCache(context, getKey(), workspaceName, systemWorkspaceCache, documentStore, translator, rootKey, nodeCache, changeBus, repositoryEnvironment()); workspaceCachesByName.put(workspaceName, workspaceCache); return workspace(workspaceName);
protected void initialize() { RepositoryCache repositoryCache = repository.repositoryCache(); if (!repositoryCache.isInitializingRepository()) { return; } Set<String> workspaceNames = repositoryCache.getWorkspaceNames(); if (workspaceNames.isEmpty()) { return; } repository.localDocumentStore().runInTransaction(() -> { for (String workspace : workspaceNames) { importInitialContent(workspace); } return null; }, 0, RepositoryCache.REPOSITORY_INFO_KEY); }
NodeKey rootKey = new NodeKey(sourceKey, workspaceKey, rootNodeId); return localStore().runInTransaction(() -> { ConcurrentMap<NodeKey, CachedNode> nodeCache = cacheForWorkspace().asMap(); ExecutionContext context = context(); logger.debug("Attempting to initialize a new ws cache for workspace '{0}' in repository '{1}' with root key '{2}'", name, getName(), rootKey); null, null); WorkspaceCache result = new WorkspaceCache(context, getKey(), name, systemWorkspaceCache, documentStore, translator, rootKey, nodeCache, changeBus, repositoryEnvironment()); logger.debug("Creating '{0}' workspace in repository '{1}' with root '{2}'", name, getName(), rootKey);
localStore().runInTransaction( () -> this.documentStore.storeIfAbsent(REPOSITORY_INFO_KEY, doc), 0); waitUntil(() -> { LOGGER.debug("Repository '{0}' is being initialized by another process; waiting until that finished or is rolled back"); SchematicEntry persistedInitializerInfo = this.documentStore.get(REPOSITORY_INFO_KEY); this.upgradingRepository = localStore().runInTransaction(() -> { LocalDocumentStore store = documentStore().localStore(); EditableDocument editor = store.edit(REPOSITORY_INFO_KEY, true); if (editor.get(REPOSITORY_UPGRADER_FIELD_NAME) == null) { LOGGER.debug("Waiting at most for 10 minutes for another process in the cluster to upgrade the content in existing repository '{0}'", name); waitUntil(() -> { Document info = documentStore().localStore().get(REPOSITORY_INFO_KEY).content(); int lastUpgradeId = info.getInteger(REPOSITORY_UPGRADE_ID_FIELD_NAME, 0); return !upgrades.isUpgradeRequired(lastUpgradeId); Set<String> newWorkspaces = refreshRepositoryMetadata(false); SessionCache systemSession = createSession(context, systemWorkspaceName, false); NodeKey systemRootKey = systemSession.getRootKey(); CachedNode systemRoot = systemSession.getNode(systemRootKey); refreshWorkspace(systemWorkspaceName); systemSession = createSession(context, systemWorkspaceName, false); systemRoot = systemSession.getNode(systemRootKey);
if (!workspaceNames.contains(name)) { if (!configuration.isCreatingWorkspacesAllowed()) { throw new UnsupportedOperationException(JcrI18n.creatingWorkspacesIsNotAllowedInRepository.text(getName())); refreshRepositoryMetadata(true); SessionCache session = createSession(context, name, false); MutableCachedNode root = session.mutable(session.getRootKey()); ChildReference ref = root.getChildReferences(session).getChild(JcrLexicon.SYSTEM); Map<String, String> userData = context.getData(); DateTime timestamp = context.getValueFactories().getDateFactory().create(); RecordingChanges changes = new RecordingChanges(context.getId(), context.getProcessId(), this.getKey(), null, repositoryEnvironment.journalId()); changes.workspaceAdded(name); this.changeBus.notify(changes); return workspace(name);
String systemWorkspaceName = repoCache.getSystemWorkspaceName(); updateIndexesStatus(systemWorkspaceName, IndexManager.IndexStatus.ENABLED, IndexManager.IndexStatus.REINDEXING); NodeCache systemWorkspaceCache = repoCache.getWorkspaceCache(systemWorkspaceName); CachedNode rootNode = systemWorkspaceCache.getNode(repoCache.getSystemKey()); for (String workspaceName : repoCache.getWorkspaceNames()) { NodeCache workspaceCache = repoCache.getWorkspaceCache(workspaceName); CachedNode rootNode = workspaceCache.getNode(workspaceCache.getRootKey()); logger.debug("Starting reindex of workspace '{0}' content in '{1}' repository.", runningState.name(), workspaceName);
this.cache.setLargeStringLength(binaryStorage.getMinimumBinarySizeInBytes()); this.context.getBinaryStore().setMinimumBinarySizeInBytes(binaryStorage.getMinimumBinarySizeInBytes()); this.cache.createWorkspace(workspaceName); this.cache = new RepositoryCache(context, documentStore, config, systemContentInitializer, repositoryEnvironment, changeBus, Upgrades.STANDARD_UPGRADES); this.statistics.set(ValueMetric.WORKSPACE_COUNT, cache.getWorkspaceNames().size()); this.changeBus.unregister(other.sequencers); } else { this.sequencers = new Sequencers(this, config, cache.getWorkspaceNames());
protected final boolean hasWorkspace( String workspaceName ) { return repositoryCache().getWorkspaceNames().contains(workspaceName); }
Property accessProp = translator.getProperty(doc, name("accessControl")); boolean enabled = false; if (accessProp != null) { Property prop = translator.getProperty(doc, name("workspaces")); final Set<String> persistedWorkspaceNames = new HashSet<String>(); ValueFactory<String> strings = context.getValueFactories().getStringFactory(); localStore().runInTransaction(() -> { SchematicEntry systemEntry = documentStore().get(systemMetadataKeyStr); if (systemEntry == null) { EditableDocument doc = documentStore().localStore().edit(systemMetadataKeyStr, true); PropertyFactory propFactory = context().getPropertyFactory(); translator.setProperty(doc, propFactory.create(name("workspaces"), workspaceNames), null, null); translator.setProperty(doc, propFactory.create(name("accessControl"), accessControlEnabled), null, null);
IndexWriter writer = CompositeIndexWriter.create(incrementalIndexingProviders); RepositoryCache repositoryCache = runningState.repositoryCache(); for (String workspaceName : repositoryCache.getWorkspaceNames()) { if (logger.isDebugEnabled()) { logger.debug("Performing incremental reindexing since '{0}' for repository '{1}' on workspace '{2}'", new Date(earliestTimestamp), repositoryCache.getName(), workspaceName); WorkspaceCache workspaceCache = repositoryCache.getWorkspaceCache(workspaceName); reindexSince(workspaceCache, writer, changedNodes);
private void doUpgrade(final Upgrades.Context resources) { try { LOGGER.debug("Upgrading repository '{0}'", name); lastUpgradeId = upgrades.applyUpgradesSince(lastUpgradeId, resources); LOGGER.debug("Recording upgrade completion in repository '{0}'", name); LocalDocumentStore store = documentStore().localStore(); EditableDocument editor = store.edit(REPOSITORY_INFO_KEY, true); DateTime now = context().getValueFactories().getDateFactory().create(); editor.setDate(REPOSITORY_UPGRADED_AT_FIELD_NAME, now.toDate()); editor.setNumber(REPOSITORY_UPGRADE_ID_FIELD_NAME, lastUpgradeId); editor.remove(REPOSITORY_UPGRADER_FIELD_NAME); LOGGER.debug("Repository '{0}' is fully upgraded", name); } catch (Throwable err) { // We do NOT want an error during upgrade to prevent the repository from coming online. // Therefore, we need to catch any exceptions here an log them, but continue ... logger.error(err, JcrI18n.failureDuringUpgradeOperation, getName(), err); resources.getProblems().addError(err, JcrI18n.failureDuringUpgradeOperation, getName(), err); } }
cache.rollbackRepositoryInfo(); this.cache.startShutdown(); this.cache.completeShutdown();
for (String workspaceName : repositoryCache.getWorkspaceNames()) { JcrSession session = runningState.loginInternalSession(workspaceName); try { repositoryCache.setAccessControlEnabled(false);
final SessionCache createSystemSession( ExecutionContext context, boolean readOnly ) { return cache.createSession(context, systemWorkspaceName(), readOnly); }
private void writeInitializedAt() { LOGGER.debug("Marking repository '{0}' as fully initialized", name); LocalDocumentStore store = documentStore().localStore(); EditableDocument repositoryInfo = store.edit(REPOSITORY_INFO_KEY, true); if (repositoryInfo.get(REPOSITORY_INITIALIZED_AT_FIELD_NAME) == null) { DateTime now = context().getValueFactories().getDateFactory().create(); repositoryInfo.setDate(REPOSITORY_INITIALIZED_AT_FIELD_NAME, now.toDate()); } LOGGER.debug("Repository '{0}' is fully initialized", name); }
WorkspaceCache workspace = repositoryCache.getWorkspaceCache(workspaceName); NodeKey rootKey = workspace.getRootKey(); this.cache = repositoryCache.createSession(this.context, workspaceName, readOnly); this.rootNode = new JcrRootNode(this, this.cache.getRootKey()); this.jcrNodes.put(this.rootNode.key(), this.rootNode);
problems); long numBinaryValues = 0L; NodeKey metadataKey = repositoryCache.getRepositoryMetadataDocumentKey(); repositoryCache.changeBus().register(observer); repositoryCache.changeBus().unregister(observer); } finally {
private void createExternalWorkspaces() { Snapshot current = this.snapshot.get(); Collection<String> workspaces = current.externalSources(); for (String workspaceName : workspaces) { repository.repositoryCache().createExternalWorkspace(workspaceName, this); } }