Skip to content

Commit fd7fa8e

Browse files
authored
log node/edge counts when writing graphs (#320)
* log node/edge counts when writing graphs * collect counts during serialization to avoid walking graph twice * also log counts during deserialization
1 parent 37bfe85 commit fd7fa8e

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

core/src/main/scala/flatgraph/Graph.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ class Graph(val schema: Schema, val storagePathMaybe: Option[Path] = None) exten
157157

158158
storagePathMaybe.foreach { storagePath =>
159159
logger.info(s"closing graph: writing to storage at `$storagePath`")
160-
Serialization.writeGraph(this, storagePath)
160+
val (nodes, edges, props) = Serialization.writeGraph(this, storagePath)
161+
logger.debug(s"closed graph: wrote $nodes nodes with $edges edges and $props properties")
161162
}
162163
}
163164

core/src/main/scala/flatgraph/storage/Deserialization.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import flatgraph.{AccessHelpers, FreeSchema, GNode, Graph, Schema}
44
import flatgraph.Edge.Direction
55
import flatgraph.misc.Misc
66
import flatgraph.storage.Manifest.{GraphItem, OutlineStorage}
7+
import org.slf4j.LoggerFactory
78

89
import java.nio.channels.FileChannel
910
import java.nio.charset.StandardCharsets
@@ -14,6 +15,7 @@ import scala.collection.mutable
1415
import java.util.concurrent
1516

1617
object Deserialization {
18+
private val logger = LoggerFactory.getLogger(classOf[Deserialization.type])
1719

1820
def readGraph(
1921
storagePath: Path,
@@ -34,8 +36,11 @@ object Deserialization {
3436
try {
3537
// fixme: Use convenience methods from schema to translate string->id. Fix after we get strict schema checking.
3638
val manifest = GraphItem.read(readManifest(fileChannel))
37-
val pool = submitJob { readPool(manifest, fileChannel, zstdCtx) }
38-
val schema = schemaMaybe.getOrElse(freeSchemaFromManifest(manifest))
39+
logger.debug(
40+
s"loading graph with ${manifest.nodes.length} nodes, ${manifest.edges.length} edges, ${manifest.properties.length} properties"
41+
)
42+
val pool = submitJob { readPool(manifest, fileChannel, zstdCtx) }
43+
val schema = schemaMaybe.getOrElse(freeSchemaFromManifest(manifest))
3944
val storagePathMaybe =
4045
if (persistOnClose) Option(storagePath)
4146
else None

core/src/main/scala/flatgraph/storage/Serialization.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class WriterContext(val fileChannel: FileChannel, val executor: concurrent.Execu
220220

221221
object Serialization {
222222

223-
def writeGraph(g: Graph, storagePath: Path, requestedExecutor: Option[concurrent.ExecutorService] = None): Unit = {
223+
def writeGraph(g: Graph, storagePath: Path, requestedExecutor: Option[concurrent.ExecutorService] = None): (Int, Int, Int) = {
224224

225225
// ensure parent directory exists
226226
Option(storagePath.getParent) match {
@@ -243,7 +243,7 @@ object Serialization {
243243
}
244244
}
245245

246-
private def innerWriteGraph(g: Graph, writer: WriterContext): Unit = {
246+
private def innerWriteGraph(g: Graph, writer: WriterContext): (Int, Int, Int) = {
247247
val nodes = mutable.ArrayBuffer.empty[NodeItem]
248248
val edges = mutable.ArrayBuffer.empty[EdgeItem]
249249
val properties = mutable.ArrayBuffer.empty[PropertyItem]
@@ -288,9 +288,11 @@ object Serialization {
288288
}
289289
}
290290

291+
val counts = (nodes.size, edges.size, properties.size)
291292
val manifest = new GraphItem(nodes.toArray, edges.toArray, properties.toArray)
292293
writer.finish(manifest)
293294

295+
counts
294296
}
295297

296298
private[flatgraph] def write(bytes: Array[Byte], res: OutlineStorage, filePtr: AtomicLong, fileChannel: FileChannel): OutlineStorage = {

0 commit comments

Comments
 (0)