Commit graph

205 commits

Author SHA1 Message Date
Matthew Jaffee
a815bba520 comment cleanup 2022-05-27 11:25:17 -05:00
Matthew Jaffee
991d3d7780 remove experimental RBF Viz stuff 2022-05-27 11:25:17 -05:00
Matthew Jaffee
772496b440 "all bitmap" multi-field, single-shard ingest
This adds a shard-based import endpoint which takes bitmap data for
all field types and imports data for the whole shard transactionally.

It uses the BitmapRewriter interface to try to intelligently allow for
setting and clearing bits simultaneously without multiple writes which
is especially helpful when ingesting into int-like fields, but also
allows clear-and-then-set behavior for set fields.
2022-05-27 11:25:17 -05:00
Seebs
d63d2492b9 clear the reference to a tx from the freelistCursor
We've been seeing weird retention of Tx that shouldn't still be open, and
one possible explanation is that, until a Tx actually uses the freelist
cursor (either to allocate a page or to release it back to the freelist),
the freelistCursor statically stored in the Db object continues to have a
pointer to the previous Tx which used it, which allows a Tx, and thus its
dirty page map, to be retained forever.

I previously thought this should also nil out the page maps in the Tx, but
the more I think about it, the less I think that's a good idea. The actual
lifespan of a committed Tx should be quite short. If it *does* stick around,
it's beneficial to us as debuggers to see those large maps of dirty pages
sticking around. So after thinking about it a lot I decided not to do
that.

Similarly, when closing out a container filter (whether a filter or
a rewriter), zero out the Cursor, Tx, and filter and rewriter functions.
(We don't have to worry about the cursor's Tx, because the cursor gets
closed, which zeros its Tx and returns the cursor to the cursor pool,
too.) This likely matters a lot less, as the filters in the pool
get garbage collected "soon", but it still reduces the amount of
stuff being retained.
2022-05-17 10:32:47 -05:00
Ben Johnson
8702fac11d
Improve RBF documentation (#2034) 2022-04-25 09:13:54 -05:00
Seebs
5d1db3a4f2 handle dirty correctly even if a page split happens 2022-04-12 13:04:55 -05:00
Seebs
88a6a047d2 try to reduce seeking in ApplyRewriter a little
Slightly more careful thoughts about whether or not the cursor
is "dirty".
2022-04-12 12:24:22 -05:00
Seebs
5148974602 trust cell.BitN a few more places
Found a couple of places where we were still not trusting this, but really
we're testing it a lot more carefully now.
2022-04-12 12:24:22 -05:00
Seebs
9acc7a6019 Drop unneeded locks
The filter and rewrite logic are unlocking and relocking but I don't
think they should. I think those locks were added early on during
testing of the filter stuff, but I don't think they should be needed,
and I've been unable to find a case where they were. I think probably
I had something where a ConsiderData function was trying to run a Tx.
2022-04-12 12:24:22 -05:00
Seebs
e67beb8766 create BitmapRewriter/ApplyRewriter, parallel to BitmapFilter
This in a parallel to ApplyFilter/BitmapFilter which allows writebacks
while it's running. It's a write operation, so it needs a write lock
on the Tx, and needs to create bitmaps if they don't already exist.
The semantics are a bit messy and need better documentation still.
2022-04-12 12:24:22 -05:00
Ben Johnson
fe7c97afa0 Fix size/PageSize calculation to be int64. 2022-04-11 08:26:00 -06:00
Ben Johnson
3b8ce696bd Shrink RBF freelist & truncate data file on checkpoint 2022-04-11 08:21:44 -06:00
Ben Johnson
c4e6a6ce8a Allow fsync() to be disabled on RBF WAL only 2022-03-25 15:16:41 -06:00
Ben Johnson
52ab38d50d Clear page from RBF dirty cache on free. 2022-03-24 09:12:15 -06:00
Seebs
a6aa1097f1 listen on localhost:0 instead of :0
MacOS's firewall complains about a previously unknown app trying to
listen for network connections whenever we run go test. That's because
we *are* listening for network connections on arbitrary interfaces, not
just on localhost as we probably intended. Fix that.
2022-03-18 13:38:30 -05:00
Todd Gruben
e209759283 make maxdelete an optional param 2022-03-11 06:20:07 -06:00
Todd Gruben
4a6c0ab086 bitmapN not reliable et 2022-03-09 21:02:39 -06:00
Ben Johnson
7cad6d2973 Free previous RBF bitmap pointer page when replacing container 2022-03-08 15:05:23 -07:00
Seebs
d8b9a921b8 handle BitN when updating an existing bitmap pointer cell
We have code to correctly fill in cell.BitN when a leaf cell already
exists but isn't of the correct sort, but not to handle the case where
it already exists and *is* a BitmapPtr, but doesn't necessarily have
the right BitN value.
2022-03-07 09:16:16 -06:00
Seebs
f5954d3cc6 use a pool for containerFilter objects
We create a lot of these during a large GroupBy query or anything else
that creates a ton of filters. Use a pool so we can reuse them, since
most of their data doesn't need to be zeroed out, and typical use
patterns have a lot of sequential creation of these short-lived things
within a goroutine.
2022-02-28 14:41:30 -06:00
Seebs
67f2312150 trust cell.BitN now
We used to manually do this because we had a number of cases where
BitN wasn't being updated, but so far as we know we've fixed them
and we have run a fair amount of stuff with sanity checks on and
not hit anything, so eliminating the constant recounting on bitwise
containers seems like a win.
2022-02-28 14:41:30 -06:00
Ben Johnson
6948b18052 Add test coverage for RBF deletion 2022-02-28 12:56:24 -07:00
Seebs
7dd7557e21 don't dump stuff to stdout for tests
We have some tests that cover stuff like the DumpDot functionality,
but we don't need them to actually write to stdout during ordinary
testing. Dump to buffers which we politely ignore. Yes, we could have
used a dummy writer, but this way it's super easy to display the
contents if we find ourselves suddenly caring.
2022-02-28 11:15:52 -06:00
Seebs
3ced081271 prevent crashes when closing db
When closing, we need to wait for existing Tx to exit before truncating
files and unmapping things. This shouldn't matter, because we don't actually
close the DB until all transactions are done, normally... except for the
background usage-gathering task. But really, it's probably just better to
be conservative.

The actual logic is fancier than it looks. We can't hold db.mu.Lock during
this, or the existing Tx can't exit. So we first grab the lock, set the closed
flag, set up a waiter for all current Tx to exit, and then release the lock.
Now we wait on the current Tx exiting. Once that's done, we grab the locks.
Anything coming in that tries to start a Tx will fail out fairly quickly
because the opened flag is now false, so even if other things get those
locks before we do, they won't keep them or create new Tx.

This makes one test deadlock because it opens a Tx and never closes it,
so we change that test to close its Tx.
2022-02-28 11:15:32 -06:00
Seebs
5901bcd5d6 drop unused helper functions
I have no idea what these functions were for, but we aren't using them
so let's not have them.
2022-02-28 11:14:22 -06:00
Todd Gruben
376af2c25f adust logic to include normalFlow vs recovery after merge 2022-02-28 08:12:03 -06:00
Todd Gruben
cf1de78efd remove string keys on delete to allow for reuse 2022-02-25 16:23:54 -06:00
Ben Johnson
28c41e9b4d Fix RBF recovery when using methodical meta page detection 2022-02-24 16:05:12 -07:00
Matthew Jaffee
6cc5d198ee remove unused stuff and fix a bunch of random staticcheck issues
sorry... once I saw, I couldn't unsee
2022-02-07 15:10:10 -06:00
Travis
07cd6ec228
Clean up some of the godoc entries in rbf 2022-01-22 07:52:36 -06:00
Ben Johnson
9ebf0e2119 Upgrade go.mod to featurebase/v3 2022-01-21 10:57:05 -07:00
Seebs
d50065a16f bump timeouts on single-writer RBF Tx test
There's no correct timeout value here, really, but the intent
of this is that we first want to be sure that a second tx doesn't
successfully start before the first exits, and then that the second
*does* successfully start *after* the first exits.

Unfortunately, there's no guarantees on timely processing, and in
reality, CI can break us by waiting more than 10ms before we get
enough CPU time to do something. More generally, there's no way to
make a test like this work correctly -- no matter how long you wait
for the second Tx to start before closing the first one, it's always
possible that it *would* have started just a millisecond later even
without you closing the first one. And similarly, no matter how long
you give it to start when it's *supposed* to, it could always take
longer.

We could in principle just set this to wait for the second Tx to start
and rely on the test timeout killing us if it doesn't, but then we
don't get a useful message.

Let's optimistically hope that 10 seconds is long enough for a trivial
rollback to happen, since that doesn't need to imply writes. And I
think 50ms is a better bet for the first test, although that does
make this test close to 5x slower on non-CI hardware.
2022-01-21 11:12:10 -06:00
Seebs
37507db4ac use array containers instead of individual bitwise adds
This affects TestTx_Remove, TestTx_DeallocateToFreeList, and
TestTx_RecreateBitmap, all of which were adding hundreds of thousands
of individual bits, or more, and all of which work just as well and
produce the same behavior using largeish containers.

This reduces race-detector-test runtime from about 20 minutes to
a couple.
2022-01-19 15:19:45 -06:00
Seebs
719a30e128 shorten MultiTx test
The MultiTx test runs for a fairly long time but doesn't add much
value running that much longer, and there's no reason it should take
more than half the time we spend on this entire directory.
2022-01-19 15:19:45 -06:00
Seebs
112abcb549 use stable cursor for freelist operations
The Cursor datatype is quite large, and allocating them constantly for
ops is extremely expensive. To avoid this, we create a single stable cursor
that lives in the DB, and can be used for freelist modifications. Since the
freelist is only ever modified once at a time, this should be safe. We also
don't fully zero it between operations, we just reset the relevant parts.
2022-01-19 15:19:45 -06:00
Seebs
adcd5adb02 improve the sync.Pool used for pages, avoid excess page allocations for WAL
Several changes. One is, we don't provide a `New` for pagePool, which
allows allocPage to check whether a page was returned, and thus, zero
pages which were found in the pool, or make new pages, but never zero
pages it just created with make. We then also make many more things
which were making pages use the pool.

Reuse the same page allocation for multiple header pages dumped into
the WAL; the bitmap header pages aren't stashed in our page map,
they're only written to the disk, so we don't need to make a new page
each time, we can just make one new page for the whole batch.

Internally in the pool, we pool pointers to [PageSize]byte, rather
than slices. sync.Pool needs pointer-like things. To store a pointer
to a slice, you have to heap-allocate the slice, also. So, instead
of heap-allocating copies of these slices, we just use pointers to
the raw data.
2022-01-19 15:19:45 -06:00
Ben Johnson
a49a14652f Fix RBF WAL size check
This commit changes the max WAL size calculation to double the
number of bitmap pages in the WAL as they require an extra header
page. Previously, this was causing the WAL to be overrun and
references to those pages were outside the mmap range and caused a
panic.
2022-01-12 08:26:14 -07:00
Matthew Jaffee
34393dee09 rip out rowcache
not strictly backward compatible... hopefully no one is actually using
the rowcache config option
2022-01-11 13:49:09 -06:00
Matthew Jaffee
df88b5a78c remove a bunch of commented print statements and unecessary prints 2022-01-11 10:42:44 -06:00
Ben Johnson
af9795aa1a Avoid panics in RBF debug tooling 2022-01-03 13:13:02 -07:00
Ben Johnson
9367a62609 Add /debug/rbf endpoint for debugging 2021-12-27 09:34:43 -07:00
Ben Johnson
60f0008dec
Merge branch 'master' into rbf-check-empty-branch 2021-12-20 13:40:34 -07:00
Ben Johnson
6481b4eabe Add rbf check for empty branch pages 2021-12-20 13:24:34 -07:00
Ben Johnson
5f8a281918 Fix RBF multi-level branch delete
This commit fixes a bug in RBF where deleting all the elements in
a bitmap that has a depth greater than 2 will cause the root bitmap
to be a branch page with a cell count of zero. This breaks an
assertion in `readBranchCell()` which causes a panic post-commit.

A new assertion has been added to prevent a branch page from being
written with a zero count in the future.
2021-12-20 12:52:14 -07:00
Matthew Jaffee
0799862266 move some locks, nbd 2021-12-17 15:09:25 -06:00
Ben Johnson
57ca5591a2 Unlock rbf.DB during WAL copy & fsync() 2021-12-17 15:09:25 -06:00
Seebs
47e098c3b1 simplify txWaiter
We don't need a condition variable for a thing with a single waiter
which waits only once, and a data structure which only one side ever
modifies. That's a closable channel.
2021-12-17 15:09:25 -06:00
Seebs
994cc03e88 fix locking and list management for afterCurrentTx
Two issues: First, there was a race condition because we were never
using the mutex for anything but the condvar broadcast, second, there
was no reason for the afterCurrentTx to need to maintain the list since
we already know where in the list we are when we are waking it up.

afterCurrentTx still wants to run with the db lock held, because
the degenerate case (no outstanding Tx) means that it will be running
with it held already. That's for another commit.
2021-12-17 15:09:25 -06:00
Seebs
5764d98f6d test fixes and order of operations on changing db.PageMap
We need to update db.PageMap after we write the db, but before
we truncate the WAL, so new transactions don't pick up the old
PageMap and then get a truncated WAL.

Also, checkpoint should not abort if there's txs -- that's okay now.
2021-12-17 15:09:25 -06:00
Ben Johnson
4279e2cb2d rebase fixes 2021-12-17 15:09:25 -06:00