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

Live channel database backup #951

Merged
merged 17 commits into from Apr 19, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

BackupHandler: configure a specific mailbox

In our configuration we specify a custom bounded mailbox for our backup handler, which is
assigned by matching on its name.
  • Loading branch information...
sstone committed Apr 18, 2019
commit cc46e5c22b08a7bf46f18e0f802ab95309e5b65e
@@ -18,14 +18,6 @@ eclair {

watcher-type = "bitcoind" // other *experimental* values include "electrum"

// specific mail box for our backup handler, bounded to 1 message
// DO NOT overwrite these settings
backup-mailbox {
mailbox-type = "akka.dispatch.BoundedMailbox"
mailbox-capacity = 1
mailbox-push-timeout-time = 0
}

bitcoind {
host = "localhost"
rpcport = 18332
@@ -143,3 +135,15 @@ eclair {
private-key-file = "tor.dat"
}
}

eclair.backup-mailbox {
mailbox-type = "akka.dispatch.BoundedMailbox"
mailbox-capacity = 1
mailbox-push-timeout-time = 0
}

akka.actor.deployment {
"/*/backuphandler" {
mailbox = eclair.backup-mailbox
}
}
@@ -88,11 +88,12 @@ class Setup(datadir: File,
val config = NodeParams.loadConfiguration(datadir, overrideDefaults)
val seed = seed_opt.getOrElse(NodeParams.getSeed(datadir))
val chain = config.getString("chain")
val chaindir = new File(datadir, chain)
val keyManager = new LocalKeyManager(seed, NodeParams.makeChainHash(chain))

val database = db match {
case Some(d) => d
case None => Databases.sqliteJDBC(new File(datadir, chain))
case None => Databases.sqliteJDBC(chaindir)
}

val nodeParams = NodeParams.makeNodeParams(config, keyManager, initTor(), database)
@@ -220,7 +221,6 @@ class Setup(datadir: File,
routerTimeout = after(FiniteDuration(config.getDuration("router.init-timeout").getSeconds, TimeUnit.SECONDS), using = system.scheduler)(Future.failed(new RuntimeException("Router initialization timed out")))
_ <- Future.firstCompletedOf(routerInitialized.future :: routerTimeout :: Nil)

chaindir = new File(datadir, chain)
wallet = bitcoin match {
case Bitcoind(bitcoinClient) => new BitcoinCoreWallet(bitcoinClient)
case Electrum(electrumClient) =>
@@ -234,13 +234,14 @@ class Setup(datadir: File,
_ = wallet.getFinalAddress.map {
case address => logger.info(s"initial wallet address=$address")
}
// do not change the name of this actor. it is used in the configuration to specify a custom bounded mailbox
backupHandler = system.actorOf(
SimpleSupervisor.props(
BackupHandler.props(
nodeParams.db,
new File(chaindir, "eclair.bak.wip"),
This conversation was marked as resolved by pm47

This comment has been minimized.

Copy link
@pm47

pm47 Apr 18, 2019

Member
Suggested change
new File(chaindir, "eclair.bak.wip"),
new File(chaindir, "eclair.bak.tmp"),
new File(chaindir, "eclair.bak")
), "backup", SupervisorStrategy.Resume)
), "backuphandler", SupervisorStrategy.Resume)
)
audit = system.actorOf(SimpleSupervisor.props(Auditor.props(nodeParams), "auditor", SupervisorStrategy.Resume))
paymentHandler = system.actorOf(SimpleSupervisor.props(config.getString("payment-handler") match {
@@ -352,11 +353,8 @@ class Setup(datadir: File,

// @formatter:off
sealed trait Bitcoin

case class Bitcoind(bitcoinClient: BasicBitcoinJsonRPCClient) extends Bitcoin

case class Electrum(electrumClient: ActorRef) extends Bitcoin

// @formatter:on

case class Kit(nodeParams: NodeParams,
@@ -1,10 +1,15 @@
package fr.acinq.eclair.db

import java.io.File
import java.util.concurrent.TimeUnit

import akka.actor.{Actor, ActorLogging, Props}
import akka.actor.{Actor, ActorLogging, ActorSystem, Deploy, PoisonPill, Props}
import akka.dispatch.{BoundedMailbox, BoundedMessageQueueSemantics, NonBlockingBoundedMailbox, PriorityGenerator, RequiresMessageQueue, UnboundedPriorityMailbox}
import com.typesafe.config.{Config, ConfigFactory}
import fr.acinq.eclair.channel.ChannelPersisted

import scala.concurrent.duration.FiniteDuration


/**
* README !
@@ -25,7 +30,7 @@ import fr.acinq.eclair.channel.ChannelPersisted
* @param tmpFile temporary file
* @param backupFile final backup file
*/
class BackupHandler(databases: Databases, tmpFile: File, backupFile: File) extends Actor with ActorLogging {
class BackupHandler(databases: Databases, tmpFile: File, backupFile: File) extends Actor with RequiresMessageQueue[BoundedMessageQueueSemantics] with ActorLogging {

// we listen to ChannelPersisted events, which will trigger a backup
context.system.eventStream.subscribe(self, classOf[ChannelPersisted])
@@ -41,6 +46,9 @@ class BackupHandler(databases: Databases, tmpFile: File, backupFile: File) exten
}
}

trait BackupHandlerMailboxSemantics

object BackupHandler {
def props(databases: Databases, tmpFile: File, backupFile: File) = Props(new BackupHandler(databases: Databases, wip: File, destination: File)).withMailbox("eclair.backup-mailbox")

def props(databases: Databases, tmpFile: File, backupFile: File) = Props(new BackupHandler(databases, tmpFile, backupFile))
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.