Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In MongoDb4 NoSql appender can't specify a capped collection size bigger than 2GB #1747

Closed
jfont-teg opened this issue Sep 1, 2023 · 4 comments
Assignees
Labels
bug Incorrect, unexpected, or unintended behavior of existing code
Milestone

Comments

@jfont-teg
Copy link

Description

In MongoDb4 NoSql appender can't specify a capped collection size bigger than 2GB, due to the fact that the property is declared as a 32bits integer and is interpreted as bytes, so the maximum permissible value is 2^31 bytes = 2GB.

MongoDB has no known size limit in capped collections, I just tested it and I have been able to create a capped collection at 100GB without problem.

Configuration

Version: 2.20.0

Logs

The error that appears:

WARN StatusConsoleListener Error while converting string [26843545600] to type [int]. Using default value [null].
 java.lang.NumberFormatException: For input string: "26843545600"
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
	at java.base/java.lang.Integer.parseInt(Integer.java:660)
	at java.base/java.lang.Integer.valueOf(Integer.java:991)
	at org.apache.logging.log4j.core.config.plugins.convert.TypeConverters$IntegerConverter.convert(TypeConverters.java:278)
	at org.apache.logging.log4j.core.config.plugins.convert.TypeConverters$IntegerConverter.convert(TypeConverters.java:274)
	at org.apache.logging.log4j.core.config.plugins.convert.TypeConverters.convert(TypeConverters.java:420)
	at org.apache.logging.log4j.core.config.plugins.visitors.AbstractPluginVisitor.convert(AbstractPluginVisitor.java:151)
	at org.apache.logging.log4j.core.config.plugins.visitors.PluginBuilderAttributeVisitor.visit(PluginBuilderAttributeVisitor.java:49)
	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:187)
	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:123)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1138)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1063)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:664)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:258)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:304)
	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:621)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:694)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:711)
	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
	at org.apache.logging.log4j.kotlin.LoggingFactoryKt.loggerDelegateOf(LoggingFactory.kt:64)
	at org.apache.logging.log4j.kotlin.LoggingFactoryKt.loggerOf(LoggingFactory.kt:68)

Reproduction

<Configuration status="WARN">
    <Appenders>
        <NoSql name="MongoDb" ignoreExceptions="false">
            <!--
                Collection size = 26.843.545.600 bytes = 25GB d'espai sense comprimir
                Espai ocupat real (comprimit) al voltant d'un 10-20% = 2.5-5GB
            -->
            <MongoDb4 connection="mongodb://localhost:27017/Logs.Synchro" capped="true" collectionSize="26843545600"/>
        </NoSql>
    </Appenders>
</Configuration>

Known workaround

Creating the collection through other means and configuring its capped size seems to work. Then you need to leave out this property from the configuration file.

@vy
Copy link
Member

vy commented Sep 1, 2023

Thanks for the report @jfont-teg! I think by simply changing the type of collectionSize from int to long, we would disrupt the backward compatibility least and address your concern. Agreed?

Would you mind submitting a patch targeting 2.x branch with the following changes, please?

  1. Change the type of collectionSize field from int to long in MongoDbProvider and MongoDb4Provider classess (Please try to spot all usages of the field; in the class, in the builder, in tests, etc.)
  2. Update docs, i.e., appenders.xml
  3. Create a changelog entry file in src/changelog/.2.x.x

@vy vy self-assigned this Sep 1, 2023
@vy vy added the bug Incorrect, unexpected, or unintended behavior of existing code label Sep 1, 2023
@garydgregory
Copy link
Member

garydgregory commented Sep 1, 2023

Using a long should be OK since we use com.mongodb.client.model.CreateCollectionOptions.sizeInBytes(long). That was an flub on my part. It's more than updating the int to a long. We have to make sure we don't break existing call sites and configurations ;-) I'll see about creating a PR...

@vy
Copy link
Member

vy commented Sep 2, 2023

@jfont-teg, I have noticed your PR. ❤️ Just before that, @garydgregory simply submitted a PR without much thinking, though with all good intentions. I hope his action didn't create an impression that your PR was for nothing. Thank you so much for the report and the PR, they mean a lot to us, please keep them coming. 🤩

@vy vy added this to the 2.20.1 milestone Sep 2, 2023
@vy
Copy link
Member

vy commented Sep 2, 2023

Closing due to #1749.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect, unexpected, or unintended behavior of existing code
Projects
None yet
Development

No branches or pull requests

3 participants