Commit graph

78 commits

Author SHA1 Message Date
Mahesh Arumugam
858f889745 FeatureBase Renaming: changing go.mod module name for featurebase 2021-07-19 09:20:30 -07:00
Seebs
0e1d448baa explicitly revoke lease on shutdown
If we explicitly shut a node down, we don't want everyone else
thinking it's up for the next 5 seconds. Worse, in CI, we have random
long delays (10+ seconds) with no CPU activity at all, so we have to
set the TTL longer there. Which makes any test checking for responsive
detection of a node going down take even longer. So! We revoke
leases on our way down, and this makes the tests not take so
long, and allows us to have a reasonable timeout on the test, while
having a completely unreasonable HeartbeatTTL to make CI stop
breaking randomly.
2021-06-22 09:02:25 -05:00
Seebs
01103b26f0 make etcd bootstrap timeout configurable
It turns out that it's desireable to be able to configure the bootstrap
timeout for etcd, because during startup, we end up delaying that long
(N-1) times in series during each cluster creation, which is pointless
when we're starting the whole cluster. Reduces test runtime by several
minutes.
2021-06-22 09:02:25 -05:00
Kuba Podgórski
6bdca67882 replace roaring.Bitmap by [][]byte 2021-05-10 18:45:23 +02:00
Kuba Podgórski
b36de3146a write shards per node 2021-05-10 13:54:18 +02:00
Kuba Podgórski
2517ee1bde remove unused 2021-05-07 15:45:30 +02:00
Kuba Podgórski
a79a36232f Write remote available shards to etcd, instead of local file. 2021-05-07 15:33:18 +02:00
Seebs
0638101d2a cluster state checking cleanups and fixes
A while back we started just polling the reported cluster state of one node
when starting a cluster for tests. This works fine if we're doing fresh
new etcd queries for every single operation -- but that's insanely
expensive, it turns out.

When we use the watcher, some nodes will report stale data for "a
while", where "a while" appears to be easily a couple dozen milliseconds.
This is probably irrelevant in most real-world cases, because the common
case (detecting a node going down) means that we have at least five
seconds after a node goes down before etcd notices the lease expiring,
and a few milliseconds more or less won't matter.

But we have tests that assume either that node 0 is always the
coordinator (wrong) or that waiting for node 0 to think the cluster
is up means that every node in the cluster thinks the cluster is up,
or at least that it means that the coordinator thinks the cluster is
up. We retried later operations but not the initial ones against
the coordinator.

In fact, we probably want to wait for the entire cluster to think
it's up before we start trying things on clusters.

We also replace the "CheckClusterState" function with the existing
AwaitState call, or a new AssertState which errors out since that's
the way we usually use AwaitState anyway.

In the AwaitPrimaryState function, which used to be
AwaitCoordinatorState in a different long-lost revision, we have
to delay until a primary node is available, or fail if one does
not become available, to avoid a panic. This probably shouldn't
happen anymore, because of the last change:

Also, rovide dummy topology.Node entries before metadata is read.

During initial startup, we want to be able to do things like determine
which node is the primary, even before we've read metadata from them.

To do this, we populate the node list with dummy entries that just have
the ID (the only part we need to sort our list), and a node state of
UNKNOWN.

This breaks the fancy logic for determining whether or not to update
the node data, because the initial status of UNKNOWN matches what we
get from SetMetadata giving us new data so we end up not realizing
that this was actually a meaningful change. But actually, that's
a pretty niche optimization; we usually only get state changes when
there's an actual change in state. The updates here are cheap
and only happen after a write (or on the first query) so it's not
worth making the logic a lot fancier to make it work, when we can
just do the simple thing and update any time the dirty flag is set.

We also standardize on a 50ms delay, because 1ms delays were
really expensive when each check was hitting etcd multiple times,
and 50ms is Usually Long Enough.
2021-04-13 12:37:07 -05:00
Seebs
d1752a7af7 switch to using a watcher to watch etcd changes
This is a significant overhaul! Quite a lot of things changed here.

Basically: Prior to this, every request for data from etcd implies
requesting the current live data from etcd, and then unpacking it or
extracting it in some way. This is expensive, which is why we have
a cache in front of it.

We don't need to do that! We can use a Watch, which notifies us
of changes as changes happen. However, there's some challenges and
difficulties along the way, and there's a couple of other changes
which are included here because it's a pain to try to separate them
out.

1. We require a logger to be provided to create our internal Etcd
wrapper. We then use that logger, instead of `fmt.Printf`. This makes
debugging messages work better, and also diagnostics, and so on.

2. The internal client that we are reusing can enter a failed state
after a leader election, in which case we have to recreate the client
to have a working client. We add a new internal-use method,
`retryClient`, which wraps a function which takes an etcd client
and returns an error, and checks for leader-election type errors
and retries creating the client when they happen. That last bit
has not been successfully tested because it's actually really hard
to trigger this now. (Because it was related in part to the
amount of etcd traffic we were producing, which is reduced.)

3. The general swap over from looking things up to unpacking things
as they come in, then returning those already-unpacked things when
we get requests.

With this change, *many tests will fail*. That is addressed by
a separate commit which addresses the secondary problem, which is
that some of our test harness code was relying on the assumption
that if any node in a cluster thinks the cluster is up, every node
will. That was usually true when we were doing everything as
expensive fully-synchronized cluster checks, but becomes significantly
less reliably true in real-world cases where nodes are also
going down sometimes, or nodes are going up and down unexpectedly.
2021-04-13 12:37:07 -05:00
Seebs
6b1cd1e43b drop etcd-with-cache option
The new etcd implementation has internal caching-like behavior which is
much more reliable (it doesn't use a TTL, it just updates when there's updates
to process) so we don't need this cache.
2021-04-13 12:37:07 -05:00
tgruben
160e64fbf3
Merge branch 'master' into tds 2021-03-24 10:07:50 -05:00
Antonio Navarro Perez
6e6eb962ee Call cancel when we try to renew the lease after an error.
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2021-03-23 14:20:14 +01:00
Todd Gruben
f52b88a962 etcd tls configuration support 2021-03-22 09:10:32 -05:00
Seebs
ef8dd91077 report errors more clearly when trying to recreate leases
There's some loose ends here because really we probably want to be
using the top-level server logger, and we should fix that, but in the
mean time, let's not swallow the errors as much, because the last
line printed doesn't actually show what the error was, but it could.

To do this, we distinguish between the current error (which might
be a wrapper around DeadlineExceeded) and a previous error which
we might prefer to return, if one exists, since it's more likely
the "real" cause.
2021-03-11 19:42:10 -06:00
Seebs
1045268f01 use testhook to ensure temporary files and directories are cleaned up
In nearly all cases, we can just switch ioutil.TempDir->testhook.TempDir
and similarly for TempFile. There's one case where we can't because we
need files to be removed before tests are over.

Also in the process give identifiable names to a lot of temporary files
and make sure they're being cleaned up, and don't use "/tmp/foo" as a
file name in a test that could be running in more than one test process
at once. :)
2021-03-11 19:42:10 -06:00
Kuba Podgórski
4c787870b2 Get metadata in Tx. Fix Nodes implementation 2021-03-10 00:28:49 +01:00
Kuba Podgórski
7b005f69c6 Close resources in TestLeasedKv 2021-03-06 12:03:57 +01:00
Antonio Navarro Perez
542a98548a Breaking code at friday afternoon...
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2021-03-05 23:35:53 +01:00
Antonio Navarro Perez
2927943734 Copy paste fix.
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2021-03-05 23:35:53 +01:00
Antonio Navarro Perez
feea0fa347 Requested changes.
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2021-03-05 23:35:53 +01:00
Antonio Navarro Perez
85a43c519d Fix problem with context errors.
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2021-03-05 23:35:53 +01:00
Antonio Navarro Perez
df0064c55f Add godoc.
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2021-03-05 23:35:53 +01:00
Antonio Navarro Perez
955ab2b5a0 Requested changes
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2021-03-05 23:35:53 +01:00
Antonio Navarro Perez
851c41cd45 Implement infinite lease renewal logic.
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2021-03-05 23:35:53 +01:00
Antonio Navarro Perez
7a1e4cd2d7 Improve leased keys.
Added a leasedKV struct in charge of maintain a lease for a specific
key.

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2021-03-05 23:35:53 +01:00
Kuba Podgórski
fa293ba6c3 Address PR comments 2021-03-03 16:13:03 +01:00
Kuba Podgórski
6f7d748c8a Always Put states in Txn 2021-03-03 13:37:20 +01:00
Nia Weiss
a698eeaac2
fix more incorrect uses of KV 2021-03-02 18:35:19 -05:00
Antonio Navarro Perez
f67db5035e Add part of cache back.
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2021-03-01 19:09:31 +01:00
Antonio Navarro Perez
6f5770bf65 Fix nil pointer exception
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2021-03-01 18:39:04 +01:00
Antonio Navarro Perez
ea7643f8bf Add documentation and try to remove code.
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
2021-03-01 16:25:32 +01:00
Nia
a906a9036b
Merge pull request #1482 from niaow/force-transactional-etcd-reads
Force transactional etcd reads
2021-02-26 19:03:21 -05:00
Nia Weiss
4be4097edd
force transactional etcd reads 2021-02-26 18:29:01 -05:00
Travis
ef40bbb617
renew heartbeat lease if the lease expires while a node is unavailable 2021-02-26 16:15:06 -06:00
Kuba Podgórski
50cbb72619 Remove comments/leftovers 2021-02-25 19:00:52 +01:00
Kuba Podgórski
49dc48f057 Switch to server API for KV Get/Range 2021-02-25 18:34:24 +01:00
Kuba Podgórski
aa15e08558 Reduce number of Txn 2021-02-25 18:12:13 +01:00
Kuba Podgórski
a5f3bce3bf Use hookedClient 2021-02-25 16:56:30 +01:00
Kuba Podgórski
1623007af1 Add waitgroup - don't close the server wait for all keepaliveFunc 2021-02-25 13:41:10 +01:00
Kuba Podgórski
23f901635e Revert "Remove etcd cache"
This reverts commit 0f4b273d3a.
2021-02-25 13:41:10 +01:00
Kuba Podgórski
0f4b273d3a Remove etcd cache 2021-02-25 11:30:09 +01:00
Kuba Podgórski
1fc3d37134
Merge branch 'disco' into etcd-shared-client 2021-02-25 09:42:00 +01:00
Kuba Podgórski
01e0c44069 One shared etcd client 2021-02-25 09:39:44 +01:00
Nia Weiss
8b645e02a2
stop caching node state in Etcd 2021-02-24 17:19:27 -05:00
Seebs
8d6f97604f use testhook to run server tests so we can have post-processing and audits
This gives more consistency with the other tests and allows us to get audit
checks on the server/ tests. The tests on the clients being closed are
temporarily disabled because they tend to think the last test's clients
are "still open" for a few seconds after the test completes.
2021-02-24 11:25:46 -06:00
Seebs
9333b1b27e leaseKeepAlive: manage context and shut it down cleanly
Every usage of this just ran keepAlive func as a goroutine with a timer, using
a parent context, but the keepAlive func didn't know about that context, so
it couldn't use that context for its own messages or interactions. Change
it to create its own cancelable context from a provided parent, and use
that to control its inner behavior.

Note that we *do* still need to send the revoke at least sometimes -- otherwise
cluster states don't update correctly. But we can time that send out
rather than using context.Background(), because after a TTL's worth of time,
there's no lease to revoke anyway.

Also, add hooks for testhook tracking so we can confirm/deny that things
are getting shut down, which they weren't.
2021-02-24 11:25:46 -06:00
Travis
b5d6c632bf
stop storing a value for views in etcd 2021-02-15 14:39:52 -06:00
Seebs
82a975fd2a avoid race conditions on nodes
Turns out we sometimes modify returned nodes. Handle this better, but
also fix up some cases where we were generating node lists we didn't really
need to answer simple questions.
2021-02-15 10:20:31 -06:00
Seebs
07a014e952 cache Nodes calls in EtcdWithCache
The Peers() data is cached, but then every call still has to unmarshal JSON
and that's stunningly expensive. Let's not!
2021-02-15 10:19:56 -06:00
Travis
a6297dc48e
WIP: load schema from etcd on holder open; validate indexes, fields, views 2021-02-12 20:32:31 -06:00