Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Save pending local transactions in the database #4566

Merged
merged 17 commits into from
Feb 20, 2017
Merged

Save pending local transactions in the database #4566

merged 17 commits into from
Feb 20, 2017

Conversation

rphmeier
Copy link
Contributor

@rphmeier rphmeier commented Feb 15, 2017

Now you can schedule transactions, restart your node, and still have them propagate correctly!

Adds a "node info" column family which will be used for general local node information (in the future, sync security level and anything else we might come up with). Introduces a migration for this purpose, solidifying the implicit incompatibility between 1.5 and 1.6-era DBs which already exists due to changes in receipt format.

All non-mined (pending and future) local transactions stored, along with their conditions and restored upon startup.

Also abstracts over the Database using a KeyValueDB trait implemented for an in-memory store as well, so we no longer require I/O for most DB tests.

Part of #1966
Fixes #2336

@rphmeier rphmeier added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Feb 15, 2017
@rphmeier rphmeier changed the title Save local transactions in the database Save pending local transactions in the database Feb 15, 2017
parity/run.rs Outdated
@@ -314,6 +329,31 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
let client = service.client();
let snapshot_service = service.snapshot_service();

// initialize the local node information store.
// TODO: tick it every once in a while?
Copy link
Contributor Author

@rphmeier rphmeier Feb 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the case of a panic or other dirty exit where destructors aren't run, the list of transactions in the database won't be updated. we might want to tick periodically (once every 5 minutes?) to ensure a higher chance of transactions making it in.

Copy link
Collaborator

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, question about migration

}

#[test]
#[should_panic]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that it shouldn't panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll panic because of the assertion that the loaded set is equal to the stored. They aren't equal because loading skips all transactions with an invalid signature.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe it would be better to have assert(expected != actual, "They aren't equal because loading skips all transactions with an invalid signature.") instead? Should panic means that it can actually panic anywhere - imho it's suitable only for simple function calls not tests like this.

pub struct ToV11(Progress);


impl Migration for ToV11 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this migration necessary? I thought that you an just append new columns without copying the whole database.

On-the-fly adding new Column Families and dropping them. Both operations are reasonably fast.
https://github.com/facebook/rocksdb/wiki/Column-Families#introduction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the existing behavior is an artifact of our migration system, which was written before we had column families. We can probably add an in-place upgrade mode, but we'd still have to create a backup copy.

Not sure if that's within the scope of the PR.

Copy link
Collaborator

@tomusdrw tomusdrw Feb 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you can just get rid of the migration at all, right? (just alter v10 to return more columns and that's it) Since if I understand correctly opening a database specifying more columns should work fine.

Copy link
Contributor Author

@rphmeier rphmeier Feb 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK you have to open the database with N columns and then add the N + 1th. Our migration manager doesn't support this operation currently. It should be simple enough to add, though. Technically, the operation of adding a column family can fail, so we still have to back up a copy of the pre-migrated database to fall back on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomusdrw Separate issue filed for that: #4581

@rphmeier
Copy link
Contributor Author

Now updates the store once every 15 minutes.

@@ -212,7 +214,7 @@ impl Writable for DBTransaction {
}
}

impl Readable for Database {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KeyValueDB and KVDB? really no better naming than this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally we'd have the trait called kvdb::Database, but our rocksdb wrapper has already taken that name and I didn't want to break all existing usages of it (although the trait name KeyValueDB is arguably more descriptive). I could use a single-letter name for the generic param, but I don't think it really matters.

@gavofyork gavofyork added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Feb 20, 2017
@gavofyork gavofyork merged commit 62b340f into master Feb 20, 2017
@gavofyork gavofyork deleted the save-txq branch February 20, 2017 16:21
@rphmeier rphmeier added the B7-releasenotes 📜 Changes should be mentioned in the release notes of the next minor version release. label Mar 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. B7-releasenotes 📜 Changes should be mentioned in the release notes of the next minor version release. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants