Add dirty wallets to disc sync schedule.

There were several places where various account files (wallet, tx, or
utxo stores) were being marked as dirty, and then not being either
immediately synced to disk or marked as a dirty account so they would
be scheduled to be synced to disk.  This change adds Account functions
to mark as dirty and add the account to the map of scheduled accounts
so they won't be missed by the disk syncer goroutine.
This commit is contained in:
Josh Rickmar 2014-01-23 12:34:41 -05:00
parent bd89f076cd
commit 830829a79f
3 changed files with 37 additions and 7 deletions

View file

@ -84,6 +84,39 @@ type Account struct {
}
}
// MarkDirtyWallet marks an account's wallet as dirty, and adds the
// account to the list of dirty accounts to be schedule to be synced to
// disk. It is a runtime error to call this without holding the wallet
// writer lock.
func (a *Account) MarkDirtyWallet() {
a.dirty = true
dirtyAccounts.Lock()
dirtyAccounts.m[a] = true
dirtyAccounts.Unlock()
}
// MarkDirtyUtxoStore marks an account's utxo store as dirty, and adds
// the account to the list of dirty accounts to be schedule to be synced to
// disk. It is a runtime error to call this without holding the utxo store
// writer lock.
func (a *Account) MarkDirtyUtxoStore() {
a.UtxoStore.dirty = true
dirtyAccounts.Lock()
dirtyAccounts.m[a] = true
dirtyAccounts.Unlock()
}
// MarkDirtyTxStore marks an account's tx store as dirty, and adds the
// account to the list of dirty accounts to be schedule to be synced to
// disk. It is a runtime error to call this without holding the tx store
// writer lock.
func (a *Account) MarkDirtyTxStore() {
a.TxStore.dirty = true
dirtyAccounts.Lock()
dirtyAccounts.m[a] = true
dirtyAccounts.Unlock()
}
// Lock locks the underlying wallet for an account.
func (a *Account) Lock() error {
a.mtx.Lock()

View file

@ -112,11 +112,8 @@ func (store *AccountStore) BlockNotify(bs *wallet.BlockStamp) {
// next scheduled disk sync.
a.mtx.Lock()
a.Wallet.SetSyncedWith(bs)
a.dirty = true
a.MarkDirtyWallet()
a.mtx.Unlock()
dirtyAccounts.Lock()
dirtyAccounts.m[a] = true
dirtyAccounts.Unlock()
}
}
@ -146,7 +143,7 @@ func (store *AccountStore) RecordMinedTx(txid *btcwire.ShaHash,
sendtx.BlockHeight = blkheight
sendtx.BlockIndex = int32(blkindex)
sendtx.BlockTime = blktime
account.TxStore.dirty = true
account.MarkDirtyTxStore()
account.TxStore.Unlock()
return nil
}

View file

@ -368,7 +368,7 @@ func NtfnProcessedTx(n btcjson.Cmd, marshaled []byte) {
// Record the tx history.
a.TxStore.Lock()
a.TxStore.s.InsertRecvTx(t)
a.TxStore.dirty = true
a.MarkDirtyTxStore()
a.TxStore.Unlock()
// Notify frontends of tx. If the tx is unconfirmed, it is always
@ -404,7 +404,7 @@ func NtfnProcessedTx(n btcjson.Cmd, marshaled []byte) {
copy(u.BlockHash[:], blockHash[:])
a.UtxoStore.Lock()
a.UtxoStore.s.Insert(u)
a.UtxoStore.dirty = true
a.MarkDirtyUtxoStore()
a.UtxoStore.Unlock()
// If this notification came from mempool, notify frontends of