Skip to content

Commit

Permalink
improve log output when closing the graph (#165)
Browse files Browse the repository at this point in the history
example output:
```
2020-10-05 14:04:17.291 DEBUG uninstalled GC monitors.
2020-10-05 14:04:17.961 INFO progress of clearing references: 18.96%
2020-10-05 14:04:18.591 INFO progress of clearing references: 37.92%
2020-10-05 14:04:19.119 INFO progress of clearing references: 56.88%
2020-10-05 14:04:19.716 INFO progress of clearing references: 75.84%
2020-10-05 14:04:20.255 INFO progress of clearing references: 94.80%
2020-10-05 14:04:20.346 INFO progress of clearing references: 100.00%
2020-10-05 14:04:20.346 INFO cleared all clearable references
2020-10-05 14:04:20.346 DEBUG closing OdbStorage
```
  • Loading branch information
mpollmeier authored Oct 5, 2020
1 parent e8b446e commit 5bf2340
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions core/src/main/java/overflowdb/ReferenceManager.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package overflowdb;

import overflowdb.storage.OdbStorage;
import overflowdb.util.NamedThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import overflowdb.storage.OdbStorage;
import overflowdb.util.NamedThreadFactory;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -83,8 +83,8 @@ private void syncClearReferences(final int releaseCount) {
if (!refsToClear.isEmpty()) {
safelyClearReferences(refsToClear);
if (logger.isInfoEnabled()) logger.info("completed clearing of " + refsToClear.size() + " references");
if (logger.isDebugEnabled()) logger.debug("current clearable queue size: " + clearableRefs.size());
if (logger.isDebugEnabled()) logger.debug("references cleared in total: " + totalReleaseCount);
if (logger.isDebugEnabled()) logger.debug("remaining clearable references: " + clearableRefs.size());
if (logger.isTraceEnabled()) logger.trace("references cleared in total: " + totalReleaseCount);
}
}

Expand Down Expand Up @@ -161,17 +161,26 @@ private static SerializedNode serializeReference(NodeRef ref) {
return null;
}


/**
* writes all references to disk overflow, blocks until complete.
* useful when saving the graph
*/
public void clearAllReferences() {
int initialRefCount = clearableRefs.size();
int clearedCount = 0;
while (!clearableRefs.isEmpty()) {
int clearableRefsSize = clearableRefs.size();
logger.info("clearing all (" + clearableRefsSize + ") references - this may take some time");
try {
syncClearReferences(clearableRefsSize);
final List<NodeRef> refsToClear = collectRefsToClear(releaseCount);
if (!refsToClear.isEmpty()) {
int clearCountCurr = refsToClear.size();
safelyClearReferences(refsToClear);
clearedCount += clearCountCurr;
}

if (logger.isInfoEnabled()) {
float progressPercent = 100f * clearedCount / initialRefCount;
logger.info(String.format("progress of clearing references: %.2f%s", Float.min(100f, progressPercent), "%"));
}
} catch (Exception e) {
throw new RuntimeException("error while clearing references to disk", e);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/overflowdb/storage/OdbStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public <A extends Node> A readNode(final long id) throws IOException {
/** flush any remaining changes in underlying storage to disk */
public void flush() {
if (mvstore != null) {
logger.debug("flushing to disk");
logger.trace("flushing to disk");
mvstore.commit();
}
}
Expand Down

0 comments on commit 5bf2340

Please sign in to comment.