forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug during initialization of HttpServerInventoryView (apache#14517)
If a server is removed during `HttpServerInventoryView.serverInventoryInitialized`, the initialization gets stuck as this server is never synced. The method eventually times out (default 250s). Fix: Mark a server as stopped if it is removed. `serverInventoryInitialized` only waits for non-stopped servers to sync. Other changes: - Add new metrics for better debugging of slow broker/coordinator startup - `segment/serverview/sync/healthy`: whether the server view is syncing properly with a server - `segment/serverview/sync/unstableTime`: time for which sync with a server has been unstable - Clean up logging in `HttpServerInventoryView` and `ChangeRequestHttpSyncer` - Minor refactor for readability - Add utility class `Stopwatch` - Add tests and stubs
- Loading branch information
1 parent
b07fb2f
commit 29cc732
Showing
16 changed files
with
1,116 additions
and
476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
processing/src/main/java/org/apache/druid/java/util/common/Stopwatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.java.util.common; | ||
|
||
import com.google.common.base.Ticker; | ||
import org.joda.time.Duration; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Thread-safe wrapper over {@link com.google.common.base.Stopwatch}. | ||
* <p> | ||
* Thread safety has been limited to the start/stop methods for now as they are | ||
* the only ones that can throw an exception in an illegal state and are thus | ||
* vulnerable to race conditions. | ||
*/ | ||
public class Stopwatch | ||
{ | ||
private final com.google.common.base.Stopwatch delegate; | ||
|
||
public static Stopwatch createStarted() | ||
{ | ||
return new Stopwatch(com.google.common.base.Stopwatch.createStarted()); | ||
} | ||
|
||
public static Stopwatch createUnstarted() | ||
{ | ||
return new Stopwatch(com.google.common.base.Stopwatch.createUnstarted()); | ||
} | ||
|
||
public static Stopwatch createStarted(Ticker ticker) | ||
{ | ||
return new Stopwatch(com.google.common.base.Stopwatch.createStarted(ticker)); | ||
} | ||
|
||
private Stopwatch(com.google.common.base.Stopwatch delegate) | ||
{ | ||
this.delegate = delegate; | ||
} | ||
|
||
public synchronized void start() | ||
{ | ||
delegate.start(); | ||
} | ||
|
||
public synchronized void stop() | ||
{ | ||
delegate.stop(); | ||
} | ||
|
||
public synchronized void reset() | ||
{ | ||
delegate.reset(); | ||
} | ||
|
||
/** | ||
* Invokes {@code reset().start()} on the underlying {@link com.google.common.base.Stopwatch}. | ||
*/ | ||
public synchronized void restart() | ||
{ | ||
delegate.reset().start(); | ||
} | ||
|
||
public synchronized boolean isRunning() | ||
{ | ||
return delegate.isRunning(); | ||
} | ||
|
||
/** | ||
* Returns the milliseconds elapsed on the stopwatch. | ||
*/ | ||
public long millisElapsed() | ||
{ | ||
return delegate.elapsed(TimeUnit.MILLISECONDS); | ||
} | ||
|
||
/** | ||
* Checks if the given duration has already elapsed on the stopwatch. | ||
*/ | ||
public boolean hasElapsed(Duration duration) | ||
{ | ||
return millisElapsed() >= duration.getMillis(); | ||
} | ||
|
||
/** | ||
* Checks that the given duration has not elapsed on the stopwatch. Calling this | ||
* method is the same as {@code !stopwatch.hasElapsed(duration)}. | ||
*/ | ||
public boolean hasNotElapsed(Duration duration) | ||
{ | ||
return !hasElapsed(duration); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
processing/src/test/java/org/apache/druid/java/util/common/StopwatchTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.java.util.common; | ||
|
||
import com.google.common.testing.FakeTicker; | ||
import org.joda.time.Duration; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class StopwatchTest | ||
{ | ||
|
||
@Test | ||
public void testDuplicateStartThrowsException() | ||
{ | ||
Stopwatch stopwatch = Stopwatch.createStarted(); | ||
Assert.assertThrows(IllegalStateException.class, stopwatch::start); | ||
} | ||
|
||
@Test | ||
public void testDuplicateStopThrowsException() | ||
{ | ||
Stopwatch stopwatch = Stopwatch.createUnstarted(); | ||
Assert.assertThrows(IllegalStateException.class, stopwatch::stop); | ||
} | ||
|
||
@Test | ||
public void testMillisElapsed() | ||
{ | ||
FakeTicker fakeTicker = new FakeTicker(); | ||
Stopwatch stopwatch = Stopwatch.createStarted(fakeTicker); | ||
fakeTicker.advance(100, TimeUnit.MILLISECONDS); | ||
stopwatch.stop(); | ||
|
||
Assert.assertEquals(100, stopwatch.millisElapsed()); | ||
} | ||
|
||
@Test | ||
public void testHasElapsed() | ||
{ | ||
FakeTicker fakeTicker = new FakeTicker(); | ||
Stopwatch stopwatch = Stopwatch.createStarted(fakeTicker); | ||
fakeTicker.advance(100, TimeUnit.MILLISECONDS); | ||
stopwatch.stop(); | ||
|
||
Assert.assertTrue(stopwatch.hasElapsed(Duration.millis(50))); | ||
Assert.assertTrue(stopwatch.hasElapsed(Duration.millis(100))); | ||
Assert.assertTrue(stopwatch.hasNotElapsed(Duration.millis(101))); | ||
Assert.assertTrue(stopwatch.hasNotElapsed(Duration.millis(500))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.