forked from apache/accumulo
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcf951f
commit 9c589cd
Showing
9 changed files
with
162 additions
and
13 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
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
110 changes: 110 additions & 0 deletions
110
test/src/main/java/org/apache/accumulo/test/ScanServerMaxLatencyIT.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,110 @@ | ||
/* | ||
* 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 | ||
* | ||
* https://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.accumulo.test; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.Map; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.apache.accumulo.core.client.Accumulo; | ||
import org.apache.accumulo.core.client.AccumuloClient; | ||
import org.apache.accumulo.core.client.ScannerBase; | ||
import org.apache.accumulo.core.client.admin.NewTableConfiguration; | ||
import org.apache.accumulo.core.conf.Property; | ||
import org.apache.accumulo.core.data.Mutation; | ||
import org.apache.accumulo.core.util.Timer; | ||
import org.apache.accumulo.minicluster.ServerType; | ||
import org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl; | ||
import org.apache.accumulo.test.functional.ConfigurableMacBase; | ||
import org.apache.accumulo.test.util.Wait; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.io.Text; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ScanServerMaxLatencyIT extends ConfigurableMacBase { | ||
|
||
protected void configure(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite) { | ||
cfg.setProperty(Property.SSERV_CACHED_TABLET_METADATA_EXPIRATION, "2s"); | ||
} | ||
|
||
@Test | ||
public void testMaxLatency() throws Exception { | ||
final String[] tables = this.getUniqueNames(2); | ||
final String table1 = tables[0]; | ||
final String table2 = tables[1]; | ||
|
||
getCluster().getConfig().setNumScanServers(1); | ||
getCluster().getClusterControl().startAllServers(ServerType.SCAN_SERVER); | ||
|
||
ExecutorService executor = Executors.newCachedThreadPool(); | ||
try (var client = Accumulo.newClient().from(getClientProperties()).build()) { | ||
|
||
Wait.waitFor(() -> !client.instanceOperations().getScanServers().isEmpty()); | ||
|
||
var ntc = new NewTableConfiguration(); | ||
ntc.setProperties(Map.of(Property.TABLE_MINC_COMPACT_MAXAGE.getKey(), "2s")); | ||
client.tableOperations().create(table1, ntc); | ||
client.tableOperations().create(table2); | ||
|
||
Timer timer = Timer.startNew(); | ||
|
||
var future1 = executor.submit(createWriterTask(client, table1, timer)); | ||
var future2 = executor.submit(createWriterTask(client, table2, timer)); | ||
|
||
for (int i = 0; i < 20; i++) { | ||
Thread.sleep(1000); | ||
var eb = timer.elapsed(TimeUnit.MILLISECONDS); | ||
var es = readMaxElapsed(client, table1); | ||
System.out.println("t1 " + es + " " + (eb - es)); | ||
System.out.println("t2 " + readMaxElapsed(client, table2)); | ||
} | ||
} | ||
|
||
} | ||
|
||
private long readMaxElapsed(AccumuloClient client, String table) throws Exception { | ||
try (var scanner = client.createScanner(table)) { | ||
scanner.setConsistencyLevel(ScannerBase.ConsistencyLevel.EVENTUAL); | ||
scanner.fetchColumn(new Text("elapsed"), new Text("nanos")); | ||
return scanner.stream().mapToLong(e -> Long.parseLong(e.getValue().toString(), 10)).max() | ||
.orElse(-1); | ||
} | ||
} | ||
|
||
private static Callable<Void> createWriterTask(AccumuloClient client, String table, Timer timer) { | ||
SecureRandom random = new SecureRandom(); | ||
Callable<Void> writerTask = () -> { | ||
try (var writer = client.createBatchWriter(table)) { | ||
while (true) { | ||
var elapsed = timer.elapsed(TimeUnit.MILLISECONDS); | ||
Mutation m = new Mutation(Long.toHexString(random.nextLong())); | ||
m.put("elapsed", "nanos", "" + elapsed); | ||
writer.addMutation(m); | ||
writer.flush(); | ||
Thread.sleep(100); | ||
} | ||
} | ||
}; | ||
return writerTask; | ||
} | ||
|
||
} |