Giter Site home page Giter Site logo

Comments (8)

lonpalmer avatar lonpalmer commented on May 22, 2024

Just a note, I reported this issue earlier but it was closed as un able to reproduce. I'm reproducing it 100% now.

from nitrite-java.

anidotnet avatar anidotnet commented on May 22, 2024

Based on your description I have created below example:

fun main(args: Array<String>) {    
    for (i in 0..5) {
        saveReport(IIotReport())
    }
}

val DB_PATH: String = "iotdb.database"
val database : Nitrite by lazy { makeOrOpenDb() }

private fun makeOrOpenDb(): Nitrite {
    val db = Nitrite.builder().compressed().filePath(DB_PATH).openOrCreate()
    return db
}

fun saveReport(report: IIotReport) {
    database.getCollection("report").insert(makeDocument(report))
}

private fun makeDocument(report: IIotReport): Document {
    val doc = Document()
    doc.put("type", report.type.toString())
    doc.put("date", report.date.time)
    doc.put("sn", report.serialNumber.toString())
    doc.put("rec", report)
    return doc
}

val counter = AtomicInteger(1)

class IIotReport {
    var type: String = "test report ${counter.getAndIncrement()}"
    var date: Date = Date()
    var serialNumber: Long = System.currentTimeMillis()
}

but I am still unable to reproduce. It is writing data properly for me. Can you please work on the code I provided here and make it reproducible? If you can share your code privately that is also okay with me. Somehow, I need to reproduce it.

Please provide your environment details also - like OS, JVM version etc.

from nitrite-java.

lonpalmer avatar lonpalmer commented on May 22, 2024

This works fine on my windows 10 development work station. It fails, however on the linux production environment machine.

I could send the created database to you if that would help you understand what's going on.

from nitrite-java.

anidotnet avatar anidotnet commented on May 22, 2024

My own machine is also Ubuntu 17.10, 64bit. The problem is not with database file I think. Can you create a heap dump and check what is going on? According to the error message there might be an OOM happening. Heap dump might help you to debug it.

You can view the database yourself, using Nitrite Explorer.

from nitrite-java.

lonpalmer avatar lonpalmer commented on May 22, 2024

from nitrite-java.

lonpalmer avatar lonpalmer commented on May 22, 2024

I looked at the Heap Dump and it was very small. 3.5MB for the entire application. Nothing seemed out of the ordinary. I'm happy to send it to you if you wouldn't mind looking at it.

I have some more information for you:

  1. If I write to the database quickly (2 inserts in a couple of seconds) both inserts are successful. Then when the third insert takes more time (approx. 10s) it fails. It's like some process in Nitrite is closing the DB. Perhaps the process that writes memory cached data to the file.

from nitrite-java.

anidotnet avatar anidotnet commented on May 22, 2024

With your last description (delay of 10 sec.) I was able to reproduce the issue. The culprit is this line:

doc.put(DB_COL_REC, report)

The reason is, you are storing a java/kotlin object inside a document. Java mandates, you mark any object withSerializable if you want to binary serialize it, or you implement readObject() and writeObject(). If you don't, the object won't be serialized and a NotSerializableException will be thrown. Your report object does not implement Serializable and that's why it is throwing an exception while storing it, but MVStore library is somehow eating the exception and not bubbling it up the stack. This exception is panicking and closing the MVStore prematurely. That's why in the next write you see this exception as "store is closed".

The reason you are not able to see this error while writing in close succession is, MVStore writes data in a background thread after certain interval. By the time the write loop completes, MVStore does not writes data to disk, so you are not seeing this error. But if you introduce delay in writes, the MVStore background thread kicks in and try to writes data whatever is in the buffer. When it fails, it panics and closes the store and failing the next write.

So the remedy is - either implement Serializable for your report class, or convert your report class to a Document of primitive types, or use ObjectRepository<IIotReport> instead of NitriteCollection. ObjectRepository will convert your report class into a Document and takes care of the serialization.

Meantime, as MVStore is eating up the exception, I'll put a check of Serializable object in the code, so that user get's a proper error message.

from nitrite-java.

lonpalmer avatar lonpalmer commented on May 22, 2024

from nitrite-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.