Skip to content
laforge49 edited this page Oct 1, 2011 · 21 revisions

Transaction logs are important, no matter how robust a system. Transaction logs are recorded before an update request is processed. They can be used to build a database in the event of a failure, for a major software update, or when the size of the root block needs to be changed.

Logging is done by the TransactionComponentLog, which takes two parameters:

  1. logDirPathname - This is the pathname of the directory where log files are to be written. (A new log file is created each time the program is run.)
  2. flushLog - Optional, and when set to "true", the log file is flushed to disk after each transaction request is written. This parameter needs to be set to ensure that all the completed transactions can be recovered.

##LoggingTest

LoggingTest configures the db subsystem for logging and then does a SetRequest transaction. A small log file is created.

val systemServices = SystemServices(new ServicesRootComponentFactory)
val dbName = "smallLogging.db"
val logDirPathname = "smallLogging"
val file = new java.io.File(dbName)
file.delete
EmptyLogDirectory(logDirPathname)
val properties = new Properties
properties.put("dbPathname", dbName)
properties.put("logDirPathname", logDirPathname)
properties.put("flushLog", "true")
val db = Subsystem(
  systemServices,
  new SmallComponentFactory,
  properties = properties,
  actorId = ActorId("db"))
val results = new Results
val chain = new Chain(results)
chain.op(systemServices, Register(db))
chain.op(db, SetRequest(db, "/$", IncDesInt(null)))
Future(systemServices, chain)
systemServices.close

LoggingTest

##EmptyLogDirectory

The EmptyLogDirectory companion object deletes all the files in the given directory, if it exists.

object EmptyLogDirectory {
  def apply(logDirPathname: String) {
    val file = new java.io.File(logDirPathname)
    if (!file.exists) return
    val files = file.listFiles
    var i = 0
    while (i < files.size) {
      if (!files(i).delete) throw new IllegalStateException(
        "unable to delete log file " + files(i).getCanonicalPath)
      i += 1
    }
  }
}

EmptyLogDirectory

##SmallComponentFactory

The SmallComponentFactory configures the small datastore to use the TransactionLogComponent.

class SmallComponentFactory
  extends ComponentFactory {
  addDependency(classOf[SmallDataStoreComponentFactory])
  addDependency(classOf[TransactionLogComponentFactory])
  addDependency(classOf[TransactionsComponentFactory])
}

SmallComponentFactory


tutorial

Clone this wiki locally