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

Fix for #2030: disk space grows until restart #2031

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions avldb/src/main/scala/scorex/db/LDBFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,35 @@ case class StoreRegistry(factory: DBFactory) extends DBFactory with ScorexLoggin
}
}

def open(path: File, options: Options): DB = {
private def openOrRepair(path: File, options: Options, afterRepair: Boolean): DB = {
lock.writeLock().lock()
try {
add(path, factory.open(path, options))
} catch {
case x: Throwable =>
log.error(s"Failed to initialize storage: $x. Please check that directory $path exists and is not used by some other active node")
java.lang.System.exit(2)
null
case t: Throwable =>
if(!afterRepair) {
log.info(s"Database repair for $path is needed, starting repair")
val t0 = System.currentTimeMillis()
repair(path, options)
val t = System.currentTimeMillis()
log.info("Repair time: " + (t - t0))
lock.writeLock().unlock()
openOrRepair(path, options, afterRepair = true)
} else {
log.error(s"Failed to initialize storage: ${t.getMessage}. " +
s"Please check that directory $path exists and is not used by some other active node ", t)
java.lang.System.exit(2)
null
}
} finally {
lock.writeLock().unlock()
}
}

def open(path: File, options: Options): DB = {
openOrRepair(path, options, afterRepair = false)
}

def destroy(path: File, options: Options): Unit = {
factory.destroy(path, options)
}
Expand Down
11 changes: 5 additions & 6 deletions avldb/src/main/scala/scorex/db/LDBKVStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import spire.syntax.all.cfor
* Both keys and values are var-sized byte arrays.
*/
class LDBKVStore(protected val db: DB) extends KVStoreReader with ScorexLogging {

db.compactRange(null, null)

/** Immutable empty array can be shared to avoid allocations. */
private val emptyArrayOfByteArray = Array.empty[Array[Byte]]

Expand Down Expand Up @@ -46,12 +49,8 @@ class LDBKVStore(protected val db: DB) extends KVStoreReader with ScorexLogging
* @return - Success(()) in case of successful insertion, Failure otherwise
*/
def insert(id: K, value: V): Try[Unit] = {
try {
db.put(id, value)
Success(())
} catch {
case t: Throwable => Failure(t)
}
// todo: temporary fix for #2030
insert(Array(id), Array(value))
}

/**
Expand Down
Loading