Comments (8)
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.
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.
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.
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.
from nitrite-java.
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:
- 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.
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.
from nitrite-java.
Related Issues (20)
- nitriteMapper is null? HOT 1
- Add 4.x.x+ to maven repository
- NitriteMapper does not give enough info about the type HOT 4
- IndexingException: indexing on arrays or collections for field formula are not supported HOT 1
- Longs become Integers after export/import HOT 7
- Migrating from 3.x to 4.x: Database file is corrupted HOT 7
- possible memory leak HOT 1
- org.h2.mvstore.Chunk.accountForRemovedPage NPE HOT 2
- MVStore claims to have unsaved changes after calling nitriteDatabase.getCollection(...) HOT 5
- NitriteCollection.update slow when unrelated properties in document are indexed HOT 6
- EntityConverter toDocument HOT 3
- KotlinXSerializationMapper decodes lists to be size 1 always HOT 1
- Invalid repository type for entity where all fields are nullable (with JacksonMapperModule) HOT 3
- Possibiltity to index a field with both text and non-unique/unique filter HOT 3
- Incorrect result when searching indexed column HOT 1
- Support JPMS HOT 6
- Feature request: method for retrieving all document ids in a collection faster HOT 1
- Search for _id always returns an iterator with an element HOT 2
- org.dizitart.no2.common.tuples.Pair cannot be cast to class java.lang.Comparable HOT 4
- @Indices is not neccessary to use, multiple @Index annotations on class are allowed HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nitrite-java.