Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Allow customers to assert facts about the current transaction.#530

Closed
eoger wants to merge 1 commit into
masterfrom
eoger/tx-assertions
Closed

Allow customers to assert facts about the current transaction.#530
eoger wants to merge 1 commit into
masterfrom
eoger/tx-assertions

Conversation

@eoger
Copy link
Copy Markdown
Contributor

@eoger eoger commented Jan 22, 2018

Fixes #225

Comment thread db/src/tx.rs Outdated
partition_map: &'a PartitionMap,
schema: &'a Schema,
mentat_id_count: i64,
tx_id: Entid,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Use KnownEntid here.

Comment thread db/src/tx.rs Outdated
tx_might_update_metadata = true;
}

if e == KnownEntid(self.tx_id) && a == entids::DB_TX_INSTANT {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You haven't checked that op == OpType::Add!

IMO, the simplest way to do all this work is to make self.tx_instant Option. That means we can get rid of tx_instant_set, skip doing the datom-producing work here, and always do the work down where we used to add txInstant by using unwrap_or.

Comment thread db/src/tx.rs Outdated
}

if e == KnownEntid(self.tx_id) && a == entids::DB_TX_INSTANT {
tx_instant_set = true;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider whether it is an error to have:

[:db/tx :db/txInstant #inst "2017-01-01T10:00:00Z"]
[:db/tx :db/txInstant #inst "2017-01-01T22:00:00Z"]

Comment thread db/src/tx.rs Outdated
panic!("This type error should have been caught earlier.");
}
// TODO: INSTANT to be strictly after the last transaction
// timestamp and strictly before the current transactor timestamp.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We might want to weaken this condition — Datomic can assume correct clocks, but embedded clients cannot.

And we will need a way to bypass this, too, for syncing.

Comment thread db/src/tx.rs Outdated
non_fts_one.push((self.tx_id,
entids::DB_TX_INSTANT,
self.schema.require_attribute_for_entid(entids::DB_TX_INSTANT).unwrap(),
TypedValue::Instant(self.tx_instant),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So this would be:

self.tx_instant.map_or_else(TypedValue::current_instant, TypedValue::Instant)

Comment thread tx/src/entities.rs Outdated
match self {
TempId::Internal(x) => Some(x),
TempId::External(_) => None,
_ => None,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The trick you used to find these locations — add the enum case, look for the compile errors — stops working if you use _. Add the explicit TempId::Tx case here instead:

TempId::Internal(x) => Some(x),
TempId::Tx |
TempId::External(_) => None,

@eoger eoger force-pushed the eoger/tx-assertions branch from 87dd6a7 to e1ea288 Compare January 24, 2018 16:08
@eoger
Copy link
Copy Markdown
Contributor Author

eoger commented Jan 24, 2018

Thank you @rnewman, I have amended my patch.
Here is what I came up with regarding multiple values passed to txInstant:

[:db/add :db/tx :db/txInstant A]
[:db/add :db/tx :db/txInstant B]
// The last :db/add value is always picked up.
// Here txInstant = B.

[:db/add :db/tx :db/txInstant A]
[:db/add :db/tx :db/txInstant B]
[:db/retract :db/tx :db/txInstant B]
// If the last assertion about txInstant is a :db/retract and it corresponds to the last :db/add value, the system picks up a value.
// Here txInstant = ::now().

[:db/add :db/tx :db/txInstant A]
[:db/retract :db/tx :db/txInstant B]
// Here, txInstant = A.

@rnewman
Copy link
Copy Markdown
Collaborator

rnewman commented Jan 24, 2018

N.B., retractions need to pass through; they conceptually apply before the additions.

After working on #533 I think duplicate specifications within a single input should be an error; feel free to define a better error type ("duplicate datom") if one doesn't exist.

@eoger eoger force-pushed the eoger/tx-assertions branch from e1ea288 to 7cb44ad Compare January 29, 2018 20:28
@eoger
Copy link
Copy Markdown
Contributor Author

eoger commented Jan 29, 2018

Updated, thanks.
I removed most of the code that was in that for term in final_terms loop since #533 does the duplicate-detection heavy-lifting now.

Comment thread db/src/tx.rs
self.schema.require_attribute_for_entid(entids::DB_TX_INSTANT).unwrap(),
TypedValue::Instant(self.tx_instant),
true));
tx_instant = self.tx_instant.unwrap_or(::now());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

unwrap_or_else(TypeValue::current_instant).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hm, no, the report returns a DateTime. My bad.

Comment thread db/src/tx.rs
tx_instant = self.tx_instant.unwrap_or(::now());

// Transact [:db/add :db/txInstant NOW :db/tx] if it doesn't exist.
if self.tx_instant == None {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You always set tx_instant right above this. I don't think you need this conditional check (or the comment).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We check self.tx_instant (not tx_instant) here, which is set conditionally in https://github.com/mozilla/mentat/pull/530/files#diff-f0d16e6d633d9a7ec44f52c5f064e75fR624

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah, but the point is: we've filtered out all txInstant-setting datoms from the input. Every tx is supposed to have one. So tx_instant (the local var) is the value we want, and we should always add it to the output. Right?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh, you stripped out the continue. Got it.

@rnewman
Copy link
Copy Markdown
Collaborator

rnewman commented Jan 30, 2018

3bf7459

@rnewman rnewman closed this Jan 30, 2018
@rnewman rnewman deleted the eoger/tx-assertions branch January 30, 2018 00:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants