Skip to content

Commit

Permalink
Merge pull request #1810 from adamretter/refactor/collection-config
Browse files Browse the repository at this point in the history
Small cleanups
  • Loading branch information
dizzzz committed Apr 12, 2018
2 parents 6a19897 + 76f1d30 commit 5949303
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 207 deletions.
8 changes: 4 additions & 4 deletions src/org/exist/backup/BackupHandler.java
Expand Up @@ -33,9 +33,9 @@
*/
public interface BackupHandler {

public void backup(Collection collection, AttributesImpl attrs);
public void backup(Collection collection, SAXSerializer serializer) throws SAXException;
void backup(Collection collection, AttributesImpl attrs);
void backup(Collection collection, SAXSerializer serializer) throws SAXException;

public void backup(Document document, AttributesImpl attrs);
public void backup(Document document, SAXSerializer serializer) throws SAXException;
void backup(Document document, AttributesImpl attrs);
void backup(Document document, SAXSerializer serializer) throws SAXException;
}
19 changes: 2 additions & 17 deletions src/org/exist/collections/Collection.java
Expand Up @@ -26,6 +26,7 @@
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import javax.annotation.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
Expand Down Expand Up @@ -179,28 +180,12 @@ public interface Collection extends Resource, Comparable<Collection>, Cacheable
*/
void setCreationTime(long timestamp);

/**
* Is the Collection Configuration enabled for this Collection
*
* @return true if the Collection Configuration is enabled
*/
boolean isCollectionConfigEnabled();

/**
* Enables/disables the Should the collection configuration for this Collection.
*
* Called by {@link org.exist.storage.NativeBroker} before doing a re-index.
*
* @param collectionConfigEnabled true if the Collection Configuration should be enabled, false otherwise
*/
void setCollectionConfigEnabled(boolean collectionConfigEnabled);

/**
* Get the Collection Configuration of this Collection
*
* @param broker The database broker
*/
CollectionConfiguration getConfiguration(DBBroker broker);
@Nullable CollectionConfiguration getConfiguration(DBBroker broker);

/**
* Get the index configuration for this collection
Expand Down
51 changes: 21 additions & 30 deletions src/org/exist/collections/CollectionConfigurationManager.java
Expand Up @@ -58,23 +58,23 @@ public class CollectionConfigurationManager implements BrokerPoolService {

private static final Logger LOG = LogManager.getLogger(CollectionConfigurationManager.class);

public final static String CONFIG_COLLECTION = XmldbURI.SYSTEM_COLLECTION + "/config";
public static final String CONFIG_COLLECTION = XmldbURI.SYSTEM_COLLECTION + "/config";

/** /db/system/config **/
public final static XmldbURI CONFIG_COLLECTION_URI = XmldbURI.create(CONFIG_COLLECTION);
public static final XmldbURI CONFIG_COLLECTION_URI = XmldbURI.create(CONFIG_COLLECTION);

/** /db/system/config/db **/
public final static XmldbURI ROOT_COLLECTION_CONFIG_URI = CONFIG_COLLECTION_URI.append(XmldbURI.ROOT_COLLECTION_NAME);
public static final XmldbURI ROOT_COLLECTION_CONFIG_URI = CONFIG_COLLECTION_URI.append(XmldbURI.ROOT_COLLECTION_NAME);

public final static String COLLECTION_CONFIG_FILENAME = "collection.xconf";
public static final String COLLECTION_CONFIG_FILENAME = "collection.xconf";

public final static CollectionURI COLLECTION_CONFIG_PATH = new CollectionURI(CONFIG_COLLECTION_URI.getRawCollectionPath());
public static final CollectionURI COLLECTION_CONFIG_PATH = new CollectionURI(CONFIG_COLLECTION_URI.getRawCollectionPath());

private Map<CollectionURI, CollectionConfiguration> configurations = new HashMap<CollectionURI, CollectionConfiguration>();
private final Map<CollectionURI, CollectionConfiguration> configurations = new HashMap<>();

private Locked latch = new Locked();
private final Locked latch = new Locked();

private CollectionConfiguration defaultConfig;
private final CollectionConfiguration defaultConfig;

public CollectionConfigurationManager(final BrokerPool brokerPool) {
this.defaultConfig = new CollectionConfiguration(brokerPool);
Expand Down Expand Up @@ -117,7 +117,7 @@ public void addConfiguration(final Txn txn, final DBBroker broker, final Collect

XmldbURI configurationDocumentName = null;
// Replaces the current configuration file if there is one
final CollectionConfiguration conf = getConfiguration(broker, collection);
final CollectionConfiguration conf = getConfiguration(collection);
if (conf != null) {
configurationDocumentName = conf.getDocName();
if (configurationDocumentName != null) {
Expand Down Expand Up @@ -200,13 +200,11 @@ public List<Object> call() throws Exception {
* Retrieve the collection configuration instance for the given collection.
* This creates a new CollectionConfiguration object and recursively scans
* the collection hierarchy for available configurations.
*
* @param broker
*
* @param collection
* @return The collection configuration
* @throws CollectionConfigurationException
*/
protected CollectionConfiguration getConfiguration(DBBroker broker, Collection collection) throws CollectionConfigurationException {
protected CollectionConfiguration getConfiguration(final Collection collection) {

final CollectionURI path = new CollectionURI(COLLECTION_CONFIG_PATH);
path.append(collection.getURI().getRawCollectionPath());
Expand All @@ -218,24 +216,17 @@ protected CollectionConfiguration getConfiguration(DBBroker broker, Collection c
* the root, stopping at the first config file it finds. This should be
* more efficient, and fit more appropriately will the XmldbURI api
*/
return latch.read(new Callable<CollectionConfiguration>() {

@Override
public CollectionConfiguration call() throws Exception {

CollectionConfiguration conf = null;

while(!path.equals(COLLECTION_CONFIG_PATH)) {
conf = configurations.get(path);
if (conf != null) {
return conf;
}
path.removeLastSegment();
return latch.read(() -> {
while(!path.equals(COLLECTION_CONFIG_PATH)) {
final CollectionConfiguration conf = configurations.get(path);
if (conf != null) {
return conf;
}

// use default configuration
return defaultConfig;
path.removeLastSegment();
}

// use default configuration
return defaultConfig;
});
}

Expand Down Expand Up @@ -451,7 +442,7 @@ public void checkRootCollectionConfig(DBBroker broker) throws EXistException, Pe
transact.abort(txn);
throw new EXistException("collection " + XmldbURI.ROOT_COLLECTION_URI + " not found!");
}
final CollectionConfiguration conf = getConfiguration(broker, collection);
final CollectionConfiguration conf = getConfiguration(collection);
if (conf != null) {
// We already have a configuration document : do not erase
// it
Expand Down
38 changes: 2 additions & 36 deletions src/org/exist/collections/MutableCollection.java
Expand Up @@ -92,7 +92,6 @@ public class MutableCollection implements Collection {
@GuardedBy("lock") private ObjectHashSet<XmldbURI> subCollections = new ObjectHashSet<>(19);
private long address = BFile.UNKNOWN_ADDRESS; // Storage address of the collection in the BFile
private long created = 0;
private volatile boolean collectionConfigEnabled = true;
private boolean triggersEnabled = true;
private XMLReader userReader;
private boolean isTempCollection;
Expand Down Expand Up @@ -1253,7 +1252,6 @@ private void storeXMLInternal(final Txn transaction, final DBBroker broker, fina
document.getUpdateLock().release(LockMode.WRITE_LOCK);
broker.getBrokerPool().getProcessMonitor().endJob();
}
setCollectionConfigEnabled(true);
broker.deleteObservers();

if(info.isCreating()) {
Expand Down Expand Up @@ -1414,13 +1412,6 @@ private IndexInfo validateXMLResourceInternal(final Txn transaction, final DBBro
addObserversToIndexer(broker, indexer);
indexer.setValidating(true);

if(CollectionConfiguration.DEFAULT_COLLECTION_CONFIG_FILE_URI.equals(name)) {
// we are updating collection.xconf. Notify configuration manager
//CollectionConfigurationManager confMgr = broker.getBrokerPool().getConfigurationManager();
//confMgr.invalidateAll(getURI());
setCollectionConfigEnabled(false);
}

final DocumentTriggers trigger = new DocumentTriggers(broker, indexer, this, isTriggersEnabled() ? config : null);
trigger.setValidating(true);

Expand Down Expand Up @@ -1757,37 +1748,12 @@ public void setPermissions(final Permission permissions) throws LockException {

@Override
public CollectionConfiguration getConfiguration(final DBBroker broker) {
if(!isCollectionConfigEnabled()) {
return null;
}

final CollectionConfigurationManager manager = broker.getBrokerPool().getConfigurationManager();
if(manager == null) {
if (manager == null) {
return null;
}
//Attempt to get configuration
CollectionConfiguration configuration = null;
try {
//TODO: AR: if a Trigger throws CollectionConfigurationException
//from its configure() method, is the rest of the collection
//configuration (indexes etc.) ignored even though they might be fine?
configuration = manager.getConfiguration(broker, this);
setCollectionConfigEnabled(true);
} catch(final CollectionConfigurationException e) {
setCollectionConfigEnabled(false);
LOG.warn("Failed to load collection configuration for '" + getURI() + "'", e);
}
return configuration;
}

@Override
public void setCollectionConfigEnabled(final boolean collectionConfigEnabled) {
this.collectionConfigEnabled = collectionConfigEnabled;
}

@Override
public boolean isCollectionConfigEnabled() {
return collectionConfigEnabled;
return manager.getConfiguration(this);
}

@Override
Expand Down

0 comments on commit 5949303

Please sign in to comment.