Recovery - laforge49/Asynchronous-Functional-Programming GitHub Wiki
The log files can be used to rebuild a database in the event of database corruption or to resize the root block. Recovery is quite fast, as each log file is processed as a single transaction. And since the small database uses only a single block, this means that there is a single write to the database for each log file processed.
##RecoveryTest
Step 1: Create a database and modify it.
val systemServices = SystemServices(new ServicesRootComponentFactory)
val dbName = "smallrecovery.db"
val logDirPathname = "smallRecovery"
val file = new java.io.File(dbName)
file.delete
EmptyLogDirectory(logDirPathname)
val properties = new Properties
properties.put("dbPathname", dbName)
properties.put("logDirPathname", logDirPathname)
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
Step 2: Perform 2 more updates.
val systemServices = SystemServices(new ServicesRootComponentFactory)
val dbName = "smallrecovery.db"
val logDirPathname = "smallRecovery"
val properties = new Properties
properties.put("dbPathname", dbName)
properties.put("logDirPathname", logDirPathname)
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, "/$", IncDesString(null)))
chain.op(db, SetRequest(db, "/$", IncDesBytes(null)))
Future(systemServices, chain)
systemServices.close
Step 3: Rebuild the database.
val systemServices = SystemServices(new ServicesRootComponentFactory)
val dbName = "smallrecovery.db"
val logDirPathname = "smallRecovery"
val file = new java.io.File(dbName)
file.delete
val properties = new Properties
properties.put("dbPathname", dbName)
properties.put("logDirPathname", logDirPathname)
val db = Subsystem(
systemServices,
new SmallRecoveryComponentFactory,
properties = properties,
actorId = ActorId("db"))
val results = new Results
val chain = new Chain(results)
chain.op(systemServices, Register(db))
chain.op(db, Recover())
Future(systemServices, chain)
systemServices.close
Output.
recovering smallRecovery\2011-10-04_02-02-11_897.jnl
recovering smallRecovery\2011-10-04_02-02-11_910.jnl
Step 4: Query the contents of the database.
val systemServices = SystemServices(new ServicesRootComponentFactory)
val dbName = "smallrecovery.db"
val logDirPathname = "smallRecovery"
val properties = new Properties
properties.put("dbPathname", dbName)
properties.put("logDirPathname", logDirPathname)
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, GetRequest(db, "/$"))
println(Future(systemServices, chain))
systemServices.close
Output.
org.agilewiki.incDes.IncDesBytes@38717323
##SmallRecoveryComponentFactory
This factory includes two components in the subsystem used for recovery: SmallDataStoreRecoveryComponentFactory and SmallTransactionsComponentFactory.
class SmallRecoveryComponentFactory
extends ComponentFactory {
addDependency(classOf[SmallDataStoreRecoveryComponentFactory])
addDependency(classOf[SmallTransactionsComponentFactory])
}