Skip to content

Commit

Permalink
Adds initial configuration part
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Reinhart <patrick@reini.net>
  • Loading branch information
reinhapa committed Jan 24, 2024
1 parent 65ddfeb commit cf86b52
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
34 changes: 31 additions & 3 deletions exist-core/src/main/java/org/exist/util/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.exist.start.Main;
import org.exist.storage.lock.LockManager;
import org.exist.storage.lock.LockTable;
import org.exist.util.io.ContentFilePool;
import org.exist.xquery.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -111,7 +112,6 @@
import static org.exist.storage.XQueryPool.MAX_STACK_SIZE_ATTRIBUTE;
import static org.exist.storage.XQueryPool.POOL_SIZE_ATTTRIBUTE;
import static org.exist.storage.XQueryPool.PROPERTY_MAX_STACK_SIZE;
import static org.exist.storage.XQueryPool.PROPERTY_POOL_SIZE;
import static org.exist.storage.journal.Journal.PROPERTY_RECOVERY_JOURNAL_DIR;
import static org.exist.storage.journal.Journal.PROPERTY_RECOVERY_SIZE_LIMIT;
import static org.exist.storage.journal.Journal.PROPERTY_RECOVERY_SYNC_ON_COMMIT;
Expand All @@ -123,6 +123,8 @@
import static org.exist.util.ParametersExtractor.PARAMETER_ELEMENT_NAME;
import static org.exist.util.XMLReaderObjectFactory.PROPERTY_VALIDATION_MODE;
import static org.exist.util.XMLReaderPool.XmlParser.*;
import static org.exist.util.io.ContentFilePool.PROPERTY_IN_MEMORY_SIZE;
import static org.exist.util.io.VirtualTempPath.DEFAULT_IN_MEMORY_SIZE;
import static org.exist.xquery.FunctionFactory.*;
import static org.exist.xquery.XQueryContext.*;
import static org.exist.xquery.XQueryWatchDog.PROPERTY_OUTPUT_SIZE_LIMIT;
Expand Down Expand Up @@ -316,6 +318,11 @@ public Configuration(@Nullable String configFilename, Optional<Path> existHomeDi
configureValidation(existHomeDirname, (Element) validations.item(0));
}

//RPC server
final NodeList rpcServer = doc.getElementsByTagName("rpc-server");
if (rpcServer.getLength() > 0) {
configureRpcServer(existHomeDirname, (Element) rpcServer.item(0));
}
} catch (final SAXException | IOException | ParserConfigurationException e) {
LOG.error("error while reading config file: {}", configFilename, e);
throw new DatabaseConfigurationException(e.getMessage(), e);
Expand Down Expand Up @@ -1217,8 +1224,8 @@ private void configureXQueryPool(final Element queryPool) {
if (maxPoolSize != null) {

try {
config.put(PROPERTY_POOL_SIZE, Integer.valueOf(maxPoolSize));
LOG.debug(PROPERTY_POOL_SIZE + ": {}", config.get(PROPERTY_POOL_SIZE));
config.put(XQueryPool.PROPERTY_POOL_SIZE, Integer.valueOf(maxPoolSize));
LOG.debug(XQueryPool.PROPERTY_POOL_SIZE + ": {}", config.get(XQueryPool.PROPERTY_POOL_SIZE));
} catch (final NumberFormatException e) {
LOG.warn(e);
}
Expand Down Expand Up @@ -1497,6 +1504,27 @@ private void configureValidation(final Optional<Path> dbHome, final Element vali
}
}

private void configureRpcServer(final Optional<Path> dbHome, final Element validation) {

Check warning on line 1507 in exist-core/src/main/java/org/exist/util/Configuration.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

exist-core/src/main/java/org/exist/util/Configuration.java#L1507

Avoid unused method parameters such as 'dbHome'.
final NodeList contentFile = validation.getElementsByTagName("content-file");
if (contentFile.getLength() > 0) {
final String inMemorySize = ((Element) contentFile.item(0)).getAttribute("in-memory-size");
if (inMemorySize != null) {
config.put(PROPERTY_IN_MEMORY_SIZE, parseInt(inMemorySize, DEFAULT_IN_MEMORY_SIZE));
if (LOG.isDebugEnabled()) {
LOG.debug("{}: {}", PROPERTY_IN_MEMORY_SIZE, config.get(DEFAULT_IN_MEMORY_SIZE));
}
}
}
final NodeList contentFilePool = validation.getElementsByTagName("content-file-pool");
if (contentFilePool.getLength() > 0) {
final String size = ((Element) contentFilePool.item(0)).getAttribute("size");
config.put(ContentFilePool.PROPERTY_POOL_SIZE, parseInt(size, -1));
if (LOG.isDebugEnabled()) {
LOG.debug("{}: {}", ContentFilePool.PROPERTY_IN_MEMORY_SIZE, config.get(ContentFilePool.PROPERTY_POOL_SIZE));

Check notice on line 1523 in exist-core/src/main/java/org/exist/util/Configuration.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

exist-core/src/main/java/org/exist/util/Configuration.java#L1523

Unnecessary use of fully qualified name 'ContentFilePool.PROPERTY_IN_MEMORY_SIZE' due to existing static import 'org.exist.util.io.ContentFilePool.PROPERTY_IN_MEMORY_SIZE'
}
}
}

/**
* Gets the value of a configuration attribute
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
* @author <a href="mailto:patrick@reini.net">Patrick Reinhart</a>
*/
public final class ContentFilePool extends GenericObjectPool<ContentFile> {
public static final String PROPERTY_POOL_SIZE = "content-file.pool.size";
public static final String PROPERTY_IN_MEMORY_SIZE = "content-file.in-memory-size";
public static final String PROPERTY_IN_MEMORY_SIZE = "rpc-server.content-file.in-memory-size";
public static final String PROPERTY_POOL_SIZE = "rpc-server.content-file-pool.size";

public ContentFilePool(final TemporaryFileManager tempFileManager, final Configuration config, final int maxIdle) {
super(new ContentFilePoolObjectFactory(tempFileManager, toInMemorySize(config)), toPoolConfig(config, maxIdle));
Expand All @@ -47,7 +47,7 @@ private static GenericObjectPoolConfig<ContentFile> toPoolConfig(final Configura
poolConfig.setLifo(true);
poolConfig.setMaxIdle(maxIdle);
poolConfig.setMaxTotal(config.getInteger(PROPERTY_POOL_SIZE));
poolConfig.setJmxNameBase("org.exist.management.exist:type=VirtualTempPathPool");
poolConfig.setJmxNameBase("org.exist.management.exist:type=ContentFilePool");
return poolConfig;
}

Expand Down
2 changes: 1 addition & 1 deletion exist-distribution/src/main/config/conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@
- max-in-memory-size:
Defines the maximum in memory hold data before storing on temporary disk space
-->
<content-file max-in-memory-size="4196"/>
<content-file in-memory-size="4196"/>
<!--
Defines content file pool handling.
Expand Down
4 changes: 2 additions & 2 deletions schema/conf.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="max-in-memory-size" type="xs:integer" default="4196">
<xs:attribute name="in-memory-size" type="xs:integer" default="4196">
<xs:annotation>
<xs:documentation>
Defines the maximum amount of bytes stored in memory for each content file instance.
Expand All @@ -432,7 +432,7 @@
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="size" type="xs:integer" default="10">
<xs:attribute name="size" type="xs:integer" default="-1">
<xs:annotation>
<xs:documentation>
Defines the maximum content file pool size. If this size is exhausted an error is thrown. Using -1 sets no limit.
Expand Down

0 comments on commit cf86b52

Please sign in to comment.