Repository navigation
Online Indexer: replace the synchronized runner with a heartbeat - #3530
Conversation
89d0263 to
f318f65
Compare
a680857 to
83830c6
Compare
ScottDugas
left a comment
There was a problem hiding this comment.
I didn't get a chance to look at all of the code, we can discuss some of the things offline.
| @@ -180,7 +178,6 @@ <M extends Message> void singleRebuild( | |||
| if (!safeBuild) { | |||
There was a problem hiding this comment.
What does safeBuild here mean in this context? Do we need to continue to prevent concurrency?
There was a problem hiding this comment.
The things that had left to non-safeBuild, as it seems, are clearing and marking the index as write-only and setting constrains that, IIUIC, should not be happening after the previous clearing.
After so many changes in the code, maybe it is time to re-design (and possibly simplify) the singleRebuild. Should that be a separate PR?
There was a problem hiding this comment.
changing and cleaning up safeBuild should not be part of this PR.
4cf86f4 to
97d02b6
Compare
ScottDugas
left a comment
There was a problem hiding this comment.
There were also two comments left on my previous review, that I want to followup on. I resolved everything else in that review, or answered in a (I hope) definitive way, so it should be easy to go back through.
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| public class IndexingHeartbeat { |
There was a problem hiding this comment.
We discussed offline, and decided to take a balanced approach of changing the method to info, so that this is, on disk, future-proofed for being upgraded to be more generic if we want to use it elsewhere. There would still need to be some substantial changes to the code, but it would need to take a subspace instead of a store and an index.
86ad032 to
2a9f7e5
Compare
2a9f7e5 to
d3b4baa
Compare
921fd82 to
a8eff82
Compare
| } | ||
|
|
||
| protected static boolean shouldLessenWork(@Nullable FDBException ex) { | ||
| protected static boolean doNotLessenWork(@Nullable FDBException ex) { |
There was a problem hiding this comment.
Why are you inverting this method, this seems completely unrelated to the change at hand.
There was a problem hiding this comment.
Tried to please an idea warning. But you are right, it is unreadable. Converting back...
| FDBRecordStoreTestBase.RecordMetaDataHook hook = myHook(sourceIndex, tgtIndex); | ||
| openSimpleMetaData(hook); | ||
|
|
||
| Semaphore pauseMutualBuildSemaphore = new Semaphore(1); |
There was a problem hiding this comment.
Doing it in a followup PR sounds good. I think you could make it a little better by making a class ConfigLoaderThatPausesAfterOnePass that could then store all of these semaphores, and have some more helpful.
There might be something even better, but we're probably getting diminishing returns here, and trying to clean this up more isn't worth it.
To be clear, looking to see if some other tests could take advantage of pauseAfterOnePass in a followup PR sounds good, but it's probably not worth creating something more full-featured.
ScottDugas
left a comment
There was a problem hiding this comment.
Teamscale is complaining about two test gaps, these seem easy enough to add coverage in the test you already have.
There's also a few test methods that are beyond the length, or nesting depth threshold, probably worth addressing those.
alecgrieser
left a comment
There was a problem hiding this comment.
A few comments. Some of these are pretty mechanical, and some of them are more about interrogating the design so that I understand what this is trying to accomplish or how certain edge cases work
| byte[] value = IndexBuildProto.IndexBuildHeartbeat.newBuilder() | ||
| .setInfo(info) | ||
| .setGenesisTimeMilliseconds(genesisTimeMilliseconds) | ||
| .setHeartbeatTimeMilliseconds(nowMilliseconds()) |
There was a problem hiding this comment.
Why put the heartbeat time (nowMilliseconds()) rather than the expiration time (nowMilliseconds() + leaseLength)? The approach in the code (which differs from how synchronized sessions worked) means that if you have multiple instances looking at the same lock, they might have different ideas as to when the current lock is set to expire
There was a problem hiding this comment.
That is correct, but this is by design.
A potential scenario is having one indexer that is more aggressive with its lock stealing than another (let's say - the first was triggered manually and the other by a background job). With the current code, the caller can do something similar by avoiding the sync lock altogether - which is not ideal.
There was a problem hiding this comment.
Hm, okay. I think it would be good if we could document the reasoning for that decision, because it's non-obvious, at least to me. The idea that you want to be able to pre-empt more aggressively is particularly weird to me, but that may be because I've still got the old mental model in my head. I'm not sure I really see the reasoning as to why you'd want a manual job to be more or less aggressive at pre-emption, though. It seems like the most common case is going to be that the lock update time is < 10 seconds ago, and setting a more aggressive time wouldn't really make much sense (unless you want to always pre-empt, I guess, though you wouldn't know from what's here anything about the current lock holder).
Maybe the important thing to note above is that every transaction updates the heartbeats, and therefore as soon as the heartbeat is pre-empted, the instance will cease work. (So there's no need to have a universally agreed upon time of exclusivity.) I can see the utility is saying, "oh, hm, our previous time period was too long/too short, which is leading to idle time/too many pre-emptions, so we want to be able to change that on the fly to be more/less aggressive."
| heartbeat = new IndexingHeartbeat(common.getIndexerId(), indexingTypeStamp.getMethod().toString(), common.config.getLeaseLengthMillis(), allowMutual); | ||
|
|
||
| return forEachTargetIndex(index -> setIndexingTypeOrThrow(store, continuedBuild, index, indexingTypeStamp)); | ||
| return forEachTargetIndex(index -> setIndexingTypeOrThrow(store, continuedBuild, index, indexingTypeStamp) |
There was a problem hiding this comment.
I'm trying to reason about the desired flow here. It seems like the simplest case is that you have a mutual by records index build going, in which case the heartbeat plus the indexing stamp check would let you continue by inserting a new entry into the store. If you had a non-mutual indexing by records going, would you be blocked from starting a mutual record build? if so, is it just the type stamp that's blocking it?
Is there a way to force a build to stop and then to resume a new build, or to otherwise change the type of build that's ongoing?
Maybe put another way: what is the point of the heartbeats for mutual indexers? Is it just to prevent us from starting a non-mutual indexer when we have mutual indexing going on?
There was a problem hiding this comment.
(exclusive to mutual:)
if it is explicitly allowed by the user (according to policy.shouldAllowTypeConversionContinue)
the switching to mutual is allowed and the type stamp is changing. This will cause the exclusive session to quit at the next transaction and the mutual one will run alone (or with its mutual friends sessions).
(force a build to stop and then to resume)
Beside the conversion system, there is also indexing blocking/unblocking (see OnlineIndexer.blockIndexBuilds API). This is designed to control the flow. Combined the conversion, it also allows gracefully stopping one session and then continue with a conversion (with or without a lock key).
(what is the point of the heartbeats for mutual indexers)
It provides visibility of the current active sessions. This can be used by either other indexers or by background processes that need to decide whether or not to add another mutual indexer to the existing ones.
There was a problem hiding this comment.
I see. This is getting a little complicated, and it seems like we need some kind of operator documentation with, like, diagrams. Perhaps for a different PR.
I believe this means that we wouldn't be able to use the heartbeats as a way to terminate specific instances (e.g., if there was some rogue process that we wanted to control)? Maybe that's fine.
Using the heartbeats to know how many (active) mutual indexers makes some amount of sense. I see that's sort of in the documentation now
| public CompletableFuture<Void> checkAndUpdateHeartbeat(@Nonnull FDBRecordStore store, @Nonnull Index index) { | ||
| // complete exceptionally if non-mutual, other exists | ||
| if (allowMutual) { | ||
| updateHeartbeat(store, index); |
There was a problem hiding this comment.
Do mutual indexers need to ensure that their heart beat is still there? This is currently a blind write, I think, which feels a bit odd. I would have thought that part of the point of this was to allow for other processes to halt this indexer, but if we don't read the key, I don't see how we'd get that benefit. (I agree that there's no reason to look at the other heartbeats with mutual indexing, as those should be allowed to change during indexing without causing a fuss.)
There was a problem hiding this comment.
The heartbeat was not meant for flow control. We have the type-stamp (with or without block) for that. See IndexingBase.isTypeStampBlocked.
There was a problem hiding this comment.
I guess this is fine, then. A blind write still seems weird to me, given that it means that another process can't halt this particular indexer by deleting this heartbeat key, whereas that's true for the other heartbeat keys.
ad2c988 to
e190d3e
Compare
|
Resolved conflicts.. |
| byte[] value = IndexBuildProto.IndexBuildHeartbeat.newBuilder() | ||
| .setInfo(info) | ||
| .setGenesisTimeMilliseconds(genesisTimeMilliseconds) | ||
| .setHeartbeatTimeMilliseconds(nowMilliseconds()) |
There was a problem hiding this comment.
Hm, okay. I think it would be good if we could document the reasoning for that decision, because it's non-obvious, at least to me. The idea that you want to be able to pre-empt more aggressively is particularly weird to me, but that may be because I've still got the old mental model in my head. I'm not sure I really see the reasoning as to why you'd want a manual job to be more or less aggressive at pre-emption, though. It seems like the most common case is going to be that the lock update time is < 10 seconds ago, and setting a more aggressive time wouldn't really make much sense (unless you want to always pre-empt, I guess, though you wouldn't know from what's here anything about the current lock holder).
Maybe the important thing to note above is that every transaction updates the heartbeats, and therefore as soon as the heartbeat is pre-empted, the instance will cease work. (So there's no need to have a universally agreed upon time of exclusivity.) I can see the utility is saying, "oh, hm, our previous time period was too long/too short, which is leading to idle time/too many pre-emptions, so we want to be able to change that on the fly to be more/less aggressive."
| public CompletableFuture<Void> checkAndUpdateHeartbeat(@Nonnull FDBRecordStore store, @Nonnull Index index) { | ||
| // complete exceptionally if non-mutual, other exists | ||
| if (allowMutual) { | ||
| updateHeartbeat(store, index); |
There was a problem hiding this comment.
I guess this is fine, then. A blind write still seems weird to me, given that it means that another process can't halt this particular indexer by deleting this heartbeat key, whereas that's true for the other heartbeat keys.
| heartbeat = new IndexingHeartbeat(common.getIndexerId(), indexingTypeStamp.getMethod().toString(), common.config.getLeaseLengthMillis(), allowMutual); | ||
|
|
||
| return forEachTargetIndex(index -> setIndexingTypeOrThrow(store, continuedBuild, index, indexingTypeStamp)); | ||
| return forEachTargetIndex(index -> setIndexingTypeOrThrow(store, continuedBuild, index, indexingTypeStamp) |
There was a problem hiding this comment.
I see. This is getting a little complicated, and it seems like we need some kind of operator documentation with, like, diagrams. Perhaps for a different PR.
I believe this means that we wouldn't be able to use the heartbeats as a way to terminate specific instances (e.g., if there was some rogue process that we wanted to control)? Maybe that's fine.
Using the heartbeats to know how many (active) mutual indexers makes some amount of sense. I see that's sort of in the documentation now
| if (!otherIndexerId.equals(this.indexerId)) { | ||
| final IndexBuildProto.IndexBuildHeartbeat otherHeartbeat = IndexBuildProto.IndexBuildHeartbeat.parseFrom(kv.getValue()); | ||
| final long age = now - otherHeartbeat.getHeartbeatTimeMilliseconds(); | ||
| if (age > TimeUnit.DAYS.toMillis(-1) && age < leaseLength) { |
There was a problem hiding this comment.
Hm, I'm not sure I agree that this age > -1 days think makes sense, as it means that if you had two instances that were really out dyssynchronized, then one would attempt to take the lock, see that the age is < -1 days, and pre-empt, then the other might look and see that the age is > 1 days, and also pre-empt, and now you're in a pre-emption cycle. If we do keep it, I think noting that this is there because we're worried about extreme clock skew is probably a good idea.
d7d3ceb to
1d6f001
Compare
|
Rebased + resolved conflicts. |
Each indexing session, for each index, will create a key-value heartbeat of the format:
[prefix, xid] -> [indexing-type, genesis time, heartbeat time]
Indexing session that are expected to be exclusive will throw an exception if another, active, session exists.
Motivation:
1. Represent the heartbeat in every index during multi target indexing (currently - only the master index has a sync lock)
2. Keep a heartbeat during mutual indexing, which can allow better automatic decision making
3. Decide about exclusiveness according to the indexing method (currently - user input)
Resolve FoundationDB#3529
1d6f001 to
2483713
Compare
|
Rebased + fixed conflicts |
…ndexing heartbeat) As a follow up to FoundationDB#3530, finalize the remove deperecated API functions.
…ndexing heartbeat) As a follow up to FoundationDB#3530, finalize the remove deperecated API functions.
…ndexing heartbeat) As a follow up to FoundationDB#3530, finalize the remove deperecated API functions.
…ndexing heartbeat) As a follow up to FoundationDB#3530, finalize the remove deperecated API functions.
Each indexing session, for each index, will create a key-value heartbeat of the format:
[prefix, xid] -> [indexing-type, genesis time, heartbeat time]Indexing session that are expected to be exclusive will throw an exception if another, active, session exists.
Motivation:
1. Represent the heartbeat in every index during multi target indexing (currently - only the master index has a sync lock)
2. Keep a heartbeat during mutual indexing, which can allow better automatic decision making
3. Decide about exclusiveness according to the indexing method (currently - user input)
With this change, the equivalent of a sync lock will be determined by the indexing type and cannot be set by the users. The index configuration function
setUseSynchronizedSessionwill have no effect on the indexing process.During graduate code upgrade on multiple servers, there may be a situation where one server is indexing with a synchronized session lock, while another server builds the same index with an exclusive heartbeat "lock". If that happens:
a) There will be no more than two concurrent active sessions
b) The indexing sessions will conflict each other until one of the indexers will give up. While this may be not optimal, the generated index will be valid.
Resolve #3529