roachtest: tpcc-1000 roachtests have failing checks
Some roachtests that involve running tpcc-1000 are failing the tpcc checks at the end, e.g.:
I190114 15:41:47.835436 1 workload/tpcc/tpcc.go:290 check 3.3.2.1 took 162.495391ms
Error: check failed: 3.3.2.1: 12 rows returned, expected zero
The tests affected by this:
- #33624 (schemachange/index/tpcc-1000)
- #33335 (schemachange/indexrollback/tpcc-1000)
- #33151 (scrub/index-only/tpcc-1000)
- #33149 (scrub/all-checks/tpcc-1000)
- https://github.com/cockroachdb/cockroach/issues/32813#issuecomment-453920621 (cdc/tpcc-1000) is potentially related
https://teamcity.cockroachdb.com/viewLog.html?buildId=1085451&buildTypeId=Cockroach_Nightlies_WorkloadNightly&tab=buildResultsDiv seems to be the first test failure of this kind. I reproduced this failure on scrub/index-only/tpcc-1000 on a separate roachprod cluster, and ran SCRUB on the entire tpcc database, which did not turn up any anomalies.
It's not clear whether this is a schema change problem, a problem with the tests, or something else. Some next steps would be to determine whether this occurs when just running tpcc-1000 by itself, and look at what the anomalous rows are in the results of the check query.
It's running
SELECT count(*) FROM
(SELECT max(no_o_id) - min(no_o_id) - count(*) AS nod FROM new_order
GROUP BY no_w_id, no_d_id)
WHERE nod != -1
expecting 0 to be returned. The schema changes do not run on the new_order table which makes it especially confounding.
Yeah I would say that this probably isn't a schema change issue per se. When we've seen issues like this before, it's been either a problem with the test or a problem with transactionality in the database itself.
Do we run the TPC-C checks after the restore/import is finished? I'm wondering if this is possibly a problem with restore/import.
I believe we do run the checks after the restore/import, right @lucy-zhang? I think we run two sets - after the restore/import and after the test, and this problem was after the test.
Yes, the checks are run immediately after the restore/import, and they pass.
https://teamcity.cockroachdb.com/project.html?projectId=Cockroach_Nightlies&testNameId=-6687189696048107282&tab=testDetails
starting failing on Jan 11th on master
https://teamcity.cockroachdb.com/project.html?projectId=Cockroach_Nightlies&testNameId=-2631868135262591507&tab=testDetails
started failing on Jan 14th on master
https://teamcity.cockroachdb.com/project.html?projectId=Cockroach_Nightlies&testNameId=9189024510331884225&tab=testDetails
started failing on Jan 14th on master
So it does appear something changed around Jan 10-11th that is causing this problem
https://github.com/cockroachdb/cockroach/pull/33566 was a complex change that got merged before the failure.
The first failure seen was https://teamcity.cockroachdb.com/viewLog.html?buildId=1088848&tab=buildResultsDiv&buildTypeId=Cockroach_Nightlies_WorkloadNightly#testNameId-6687189696048107282
A different check failed here:
https://github.com/cockroachdb/cockroach/issues/34293
Yeah, these all look related. I'm working on isolating #33566 as the culprit now. Once that's confirmed, I'll dig into what's going wrong.
SGTM, let me know if I can be of any help.
On Mon, Jan 28, 2019 at 4:53 PM Nathan VanBenschoten < [email protected]> wrote:
Yeah, these all look related. I'm working on isolating #33566 https://github.com/cockroachdb/cockroach/pull/33566 as the culprit now. Once that's confirmed, I'll dig into what's going wrong.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cockroachdb/cockroach/issues/34025#issuecomment-458186151, or mute the thread https://github.com/notifications/unsubscribe-auth/AE135BMY2nGUdXGtJd9pipd2nDIgjWEFks5vHxz8gaJpZM4aBiGL .
@nvanbenschoten thanks for your help on this issue!
https://teamcity.cockroachdb.com/viewLog.html?buildId=1085451&buildTypeId=Cockroach_Nightlies_WorkloadNightly&tab=buildResultsDiv seems to be the first test failure of this kind.
This corresponds to 12e28159b1d8b63b56d6a48f22ebbb5c75e8ee5c, which was actually merged before https://github.com/cockroachdb/cockroach/pull/33566. That doesn't mean its sibling change 04189f59930815d7367c434b2ad617cc3cf1fcfc isn't responsible (it still probably is), but it narrows the search.
I just got a reproduction on c5516efba7bd06fad5a8f26a751aa70f74f755c7. That doesn't tell us too much since we saw it before, but it's nice to have some degree of reproducibility, even if it takes a few hours.
I convinced myself that the duplicate key value (o_w_id,o_d_id,o_id)=(979,7,3002) violates unique constraint "primary" (SQLSTATE 23505) errors are different symptoms for the same problem demonstrated by the check failures. For instance,
Error: check failed: 3.3.2.2: inequality at idx 435: order: 3010.000000, newOrder: 3010.000000, district-1: 3009.000000
is just another way of saying the the order table has an order id (3010) that does not line up with the d_next_o_id from the district table (also 3010, but should at least be 3011). This should not be possible given a properly functioning new_order transaction.
Error: check failed: 3.3.2.1: 12 rows returned, expected zero
is similar in that it demonstrates a partially applied payment txn.
These two check failures also fit a similar pattern. In both, the first write in the transaction seems to be missing. Interestingly, in both of these transactions, the writes are meant to be the most heavily contended. I suspect that we're seeing something like the following series of events:
- transaction A writes intent X for statements 1
- transaction B begins blocking on transaction A, intent X because its trying to write to the same row
- transaction A writes intents Y and Z for statements 2 and 3
- transaction B succesfully aborts transaction A and removes intent X
- transaction A's aborted record is removed (GC?)
- transaction A somehow "comes back to life" and re-writes its record either through a HeartbeatRequest or an EndTransaction request
- transaction A commits and resolves Y and Z. It fails to find X, so it throws this warning (or one of the ones below it)
Unfortunately I don't actually see a warning like that in the logs, but perhaps the transaction didn't commit at epoch 0. I'm going to add some logging in and see if I can get a repro again.
An interesting note is that these scrub and schemachange roachtests are dramatically underprovisioned, which leads to them having extremely long transactions. They run TPC-C 1000 on 3-node clusters with 4 cores each. This cluster config can usually only support around 450 warehouses before falling over.
I'm still not to the bottom of this, but it's been my main focus for about a week and feel like I'm slowly painting a full picture of what's going on. The slow reproduction cycle (1-2 times a day) doesn't make quick iteration easy.
First off, I'll retract my previous statement that the duplicate key value / 3.3.2.2 check failure is the same issue as what we see here. I've been stressing tpcc (through the roachtests listed in this issue) for the past six days on c5516efba7bd06fad5a8f26a751aa70f74f755c7 and have yet to see a single instance of this (granted I've only seen about 5 3.3.2.1 failures with 16 clusters continuously stressing this). @awoods187 seems to be able to reproduce these at-will on master and we saw the first instance about a week after we first saw the first 3.3.2.1 failure. So the conclusion I've been pushed towards is that they're not the same. If anyone wants to help, investigating that in parallel would be very helpful.
In terms of the easiest way to reproduce this issue, I've found that the scrub tests fail most frequently. I believe this is because they most severely underprovision a cluster for tpcc, leading to more transaction aborts. This is supported by the failure being slightly easier to reproduce when I dropped TxnLivenessThreshold down to 1 * base.DefaultHeartbeatInterval instead of 2 * base.DefaultHeartbeatInterval, which should cause more transaction aborts due to delayed txn heartbeats.
Another interesting point which @danhhz and I discussed in https://github.com/cockroachdb/cockroach/issues/32813#issuecomment-459091208 is that the failure usually occurs within a minute of starting load on a tpcc cluster. By dropping the load duration in the scrub tests down to 10 minutes I was able to shorten the iteration time without reducing the failure rate (noticeably?). More on why I think this is later.
Given that our prime suspect for this is 04189f59930815d7367c434b2ad617cc3cf1fcfc (although other than https://github.com/cockroachdb/cockroach/issues/33149#issuecomment-452606469, I've never seen this fail before c5516efba7bd06fad5a8f26a751aa70f74f755c7), I started by adding a lot of logging around transaction state transitions. Specifically, I logged about transaction pushes, transaction aborts, transaction record creation, transaction commits, etc. When I finally got a reproduction, I parsed all the logs, threw them into an advanced system specializing in ad-hoc query processing over large data sets (a CockroachDB cluster), and began looking for strange transaction timelines. I didn't find anything that stood out and soon realized that I had been logging so heavily for ~3 hours that most of the log files had rolled over and I was missing anything of interest. After fixing that and waiting another day for a repro, I finally had a full set of logs. Unfortunately, on its own, I still couldn't find anything that looked strange.
Since I still had the cluster up and running, I could verify that the query from check 3.3.2.1 still reproduced. The check confirmed that the year-to-date sum on a warehouse row equaled the combined year-to-date sum of all of that warehouse's districts. By adjusting it slightly, it was possible to determine the warehouse that was inconsistent and the price difference that it was inconsistent by. I took this and found that in most cases I could find a corresponding row in the history table with the same amount! I then realized just how brilliant AS OF SYSTEM TIME queries are. I could perform the query with AS OF SYSTEM TIME specifiers to determine exactly when this history row was inserted. Mapping that back to my log of transactions I was able to find the exact transaction that performed this insert. Since the warehouse table was missing this amount, I figured the transaction's intent on the warehouse table had somehow been removed prematurely. This was essentially the theory in https://github.com/cockroachdb/cockroach/issues/34025#issuecomment-458540345.
I spent a while looking at neighboring transactions in the logs and how they interacted with our suspect transaction (let's call it Txn A). Everything checked out. No one thought they had aborted A (other than after it had committed and its txn record had been removed, but that's kosher). I went back through the reproduction cycle twice more just to get more logging on intent resolution, intent removal, and txn record removal. Still, nothing popped up. I then realized I could even query the warehouse table immediately after the transaction was supposed to be committed using AOST and see the update. I found that the warehouse table had been correctly updated by Txn A. I then confirmed that the 3.3.2.1 check passed after Txn A was supposed to have committed. At this point, I was thoroughly confused.
This is when I did what I should have done in the first place and ran the 3.3.2.1 check using AOST to determine exactly when it started failing. This ended up being about 10 seconds after Txn A committed (which remember, updated w_ytd by exactly the amount it was later missing). I looked in the history table again and sure enough, found a row inserted by a transaction (call it Txn B) at the same time. It turns out that Txn B updated the warehouse row by exactly TxnB.amount - TxnA.amount. In other words, Txn B had completed ignore Txn A's original update to the warehouse row. This was classic write skew of two read-modify-write operations!
I've since seen this exact behavior on three different clusters (every repro since I started looking for it). I've even seen it four times on the same cluster once, which corresponded to a 4 rows returned, expected zero failure. Here are what I see to be the commonalities between all of these cases:
- Txn A always commits with a lower commit timestamp than Txn B's original timestamp
- Everyone always commits at epoch 0 (i.e. no restarts)
- Txn A always seems to hit a
RETRY_SERIALIZABLEerror, so I assume it's refreshing to avoid restarting (see fact #2) - Txn B usually but not always hits a
RETRY_SERIALIZABLEerror. In other words, it doesn't always refresh. - Txn A always seems to be surrounded by the following operations on its range: Add replica, Remove replica, and one or more splits. I highly suspect that this is related because it would explain why we see this so frequently at the beginning of runs.
- From what I can tell, Txn A usually seems to commit on a different leaseholder for its
warehouserange (where it's txn record is) than the leaseholder who existed when it stated. However, I can see cases where its heartbeat creates a txn record on the first and second leaseholder. Unfortunately, I've never been able to see the exact lease history of the range. - In the
4 rows returned, expected zerocase, the Txn A in all fours cases operated at essentially the exact same time, on the same range.
Since Txn B always has a higher orig timestamp than Txn A's commit timestamp (although they are active concurrently) it's baffling that Txn B misses Txn A's write. What should happen is either
- (if the read comes after the intent write) Txn B observes Txn A's write. If Txn A has already resolved its intent then it should absolutely respect it. If Txn A has not, then Txn B would start pushing Txn A. If Txn B is not able to abort Txn A then it should observe its update after the intent is resolved.
- (if the read comes before the intent write) Txn B bumps the timestamp cache to TxnB.OrigTimestamp after its read, preventing Txn A from writing without bumping TxnA.Timestamp to at least TxnB.OrigTimestamp. This timestamp bump does not happen (see fact #1).
I haven't been able to think of any way that the second mechanism could break down in general or due to any of the changes in 04189f59930815d7367c434b2ad617cc3cf1fcfc. Even if TxnB incorrectly thought that TxnA was aborted (which I don't see evidence for), I don't see evidence that it tried to remove TxnA's intent. Without removing the intent, I don't think it's possible for it to have read the previously committed value. So I think a breakdown in the second mechanism is more likely, especially because this seems to be related to lease changes. But I also don't see how that could break down.
Random theories I explored but disproved:
- the write skew is a result of a follower read gone wrong. This would explain why Txn B's read would either miss Txn A's intent/committed value or fail to prevent the intent by bumping the read timestamp cache. It turns out that
kv.closed_timestamp.follower_reads_enableddefaults to false. - Txn B performed the read portion of its UPDATE statement in a different txn (with a lower original timestamp) and performed the write portion of its UPDATE statement as Txn B. This idea is similar to what happened in https://github.com/cockroachdb/cockroach/pull/33312. Since I started looking for this, I have always seen Txn B be a result of a previously aborted txn, but that txn always tried to commit unsuccessfully with 6 intents before being aborted. This means that it couldn't have been aborted in the middle of the SQL transaction's UPDATE statement.
Any insight or wild guesses here would be helpful. This is going to delay the next Alpha (as will the duplicate key value error I mentioned above) if we can't fix it by then, so there is some urgency here.
cc. @tbg @bdarnell @petermattis
This is a fantastic write-up, though I'm afraid I don't have any good ideas to offer. One thing to keep in mind is that it is possible that https://github.com/cockroachdb/cockroach/commit/04189f59930815d7367c434b2ad617cc3cf1fcfc simply revealed a previously existing bug (perhaps one that was not exercisable prior to that change).
- In the 4 rows returned, expected zero case, the Txn A in all fours cases operated at essentially the exact same time, on the same range.
That's super curious. Something happened on that range that affected 4 different txns? I suppose this lends weight to the suspicion that an add replica, remove replica, or split, is related to the problem.
I'll sleuth some more code and read your report more thoroughly tomorrow, but I'll let this script run overnight on my worker in the hope that it reproduces. It basically merges-splits-scatters warehouses repeatedly and checks 3.3.2.1 after each iteration. I have it on c5516efba7bd06fad5a8f26a751aa70f74f755c7 currently.
Very likely unrelated, but my tpcc workload always dies with (right at the beginning, takes a few sec though):
$ ./bin/workload run tpcc --expensive-checks --warehouses 100 --ramp 30s --wait=false --tolerate-errors --duration=24h 'postgres://root@localhost:26257?sslmode=disable' --histograms tpcc.json
Error: preparing
INSERT INTO "order" (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local)
VALUES ($1, $2, $3, $4, $5, $6, $7): ERROR: root: memory budget exceeded: 10240 bytes requested, 134215680 currently allocated, 134217728 bytes in budget (SQLSTATE 53200)
That's 134mb.
Ah, nvm, that's the root budget which makes sense.
(if the read comes after the intent write) Txn B observes Txn A's write. If Txn A has already resolved its intent then it should absolutely respect it. If Txn A has not, then Txn B would start pushing Txn A. If Txn B is not able to abort Txn A then it should observe its update after the intent is resolved.
This gives me flashbacks to the time-bound iterator bug. I know there aren't any TBIs in use here, though, and it doesn't look like we can point the finger to any other rocksdb changes/features.
One thing to keep in mind is that it is possible that 04189f5 simply revealed a previously existing bug (perhaps one that was not exercisable prior to that change).
Yeah, just like pipelined writes in 2.1 exposed #30792 even though the faulty code had existed since 2.0.
This is going to delay the next Alpha (as will the duplicate key value error I mentioned above) if we can't fix it by then, so there is some urgency here.
Can we revert the changes to {Begin,Heartbeat,End}Txn instead of delaying?
I'm thinking about the way we use the txn id payload of the tscache, and how it's different between regular KV entries (where the txn id indicates a txn that is allowed to read at that timestamp) and txn records (where the txn id indicates whether we finalized our own txn or were aborted by someone else). In either case, the txn id is nilled out on a lease transfer (and, as you pointed out when this was in code review, it's been like that for a long time - consistent with the theory that this is something like #30792, an old bug that was recently exposed).
8143b458 removed the consultsTSCache flag from BeginTransaction, replacing it with the CanCreateTxnRecord method. That method has explicit logic around nil txn ids, but maybe it's incorrect. Or maybe we were unknowingly relying on the behavior of applyTSCache for BeginTransaction (which doesn't handle txn ids in quite the same way) and this broke something.