LOGGER.debug("Repository '{0}' acquired clustered-wide lock for performing initialization or verifying status", name);
// at this point we should have a global cluster-wide lock
isHoldingClusterLock = true;
}
SchematicEntry repositoryInfo = this.documentStore.localStore().get(REPOSITORY_INFO_KEY);
boolean upgradeRequired = false;
if (repositoryInfo == null) {
// Create a UUID that we'll use as the string specifying who is doing the initialization ...
String initializerId = UUID.randomUUID().toString();
// Must be a new repository (or one created before 3.0.0.Final) ...
this.repoKey = NodeKey.keyForSourceName(this.name);
this.sourceKey = NodeKey.keyForSourceName(configuration.getStoreName());
DateTime now = context.getValueFactories().getDateFactory().create();
// Store this info in the repository info document ...
EditableDocument doc = Schematic.newDocument();
doc.setString(REPOSITORY_NAME_FIELD_NAME, this.name);
doc.setString(REPOSITORY_KEY_FIELD_NAME, this.repoKey);
doc.setString(REPOSITORY_SOURCE_NAME_FIELD_NAME, configuration.getStoreName());
doc.setString(REPOSITORY_SOURCE_KEY_FIELD_NAME, this.sourceKey);
doc.setDate(REPOSITORY_CREATED_AT_FIELD_NAME, now.toDate());
doc.setString(REPOSITORY_INITIALIZER_FIELD_NAME, initializerId);
doc.setString(REPOSITORY_CREATED_WITH_MODESHAPE_VERSION_FIELD_NAME, ModeShape.getVersion());
doc.setNumber(REPOSITORY_UPGRADE_ID_FIELD_NAME, upgrades.getLatestAvailableUpgradeId());
// store the repository info
if (this.documentStore.localStore().putIfAbsent(REPOSITORY_INFO_KEY, doc) != null) {
// if clustered, we should be holding a cluster-wide lock, so if some other process managed to write under this
// key,
// smth is seriously wrong. If not clustered, only 1 thread will always perform repository initialization.
// in either case, this should not happen
throw new SystemFailureException(JcrI18n.repositoryWasInitializedByOtherProcess.text(name));
}
repositoryInfo = this.documentStore.get(REPOSITORY_INFO_KEY);
// We're doing the initialization ...
initializingRepository = true;
LOGGER.debug("Initializing the '{0}' repository", name);
} else {
// Get the repository key and source key from the repository info document ...
Document info = repositoryInfo.getContent();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Repository '{0}' already initialized at '{1}'", name,
info.get(REPOSITORY_INITIALIZED_AT_FIELD_NAME));
}
String repoName = info.getString(REPOSITORY_NAME_FIELD_NAME, this.name);