forked from pinpoint-apm/pinpoint
-
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.
[pinpoint-apm#11431] Striping span connection
- Loading branch information
Showing
12 changed files
with
426 additions
and
186 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
30 changes: 30 additions & 0 deletions
30
.../main/java/com/navercorp/pinpoint/common/hbase/async/AsyncTableWriterSelectorFactory.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,30 @@ | ||
package com.navercorp.pinpoint.common.hbase.async; | ||
|
||
import org.apache.hadoop.hbase.TableName; | ||
import org.apache.hadoop.hbase.client.AsyncConnection; | ||
import org.apache.hadoop.hbase.client.AsyncTable; | ||
|
||
import java.util.Objects; | ||
|
||
public class AsyncTableWriterSelectorFactory implements TableWriterFactory { | ||
|
||
private final ConnectionSelector selector; | ||
|
||
public AsyncTableWriterSelectorFactory(ConnectionSelector selector) { | ||
this.selector = Objects.requireNonNull(selector, "selector"); | ||
} | ||
|
||
@Override | ||
public Writer writer(TableName tableName) { | ||
AsyncConnection connection = selector.getConnection(); | ||
final AsyncTable<?> table = connection.getTable(tableName); | ||
return table::put; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AsyncTableWriterSelectorFactory{" + | ||
"selector=" + selector + | ||
'}'; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/async/ConnectionSelector.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,7 @@ | ||
package com.navercorp.pinpoint.common.hbase.async; | ||
|
||
import org.apache.hadoop.hbase.client.AsyncConnection; | ||
|
||
public interface ConnectionSelector { | ||
AsyncConnection getConnection(); | ||
} |
55 changes: 55 additions & 0 deletions
55
...ons-hbase/src/main/java/com/navercorp/pinpoint/common/hbase/async/RoundRobinSelector.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,55 @@ | ||
package com.navercorp.pinpoint.common.hbase.async; | ||
|
||
import com.navercorp.pinpoint.common.util.IOUtils; | ||
import org.apache.hadoop.hbase.client.AsyncConnection; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.io.Closeable; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class RoundRobinSelector implements ConnectionSelector, Closeable { | ||
private final Logger logger = LogManager.getLogger(this.getClass()); | ||
|
||
private final AtomicInteger mod = new AtomicInteger(0); | ||
|
||
private final AsyncConnection[] connections; | ||
|
||
public RoundRobinSelector(List<AsyncConnection> connections) { | ||
Objects.requireNonNull(connections, "connections"); | ||
this.connections = connections.toArray(new AsyncConnection[0]); | ||
} | ||
|
||
void setModKey(int mod) { | ||
this.mod.set(mod); | ||
} | ||
|
||
@Override | ||
public AsyncConnection getConnection() { | ||
final int index = getIndex(); | ||
return connections[index]; | ||
} | ||
|
||
private int getIndex() { | ||
final long next = mod.getAndIncrement(); | ||
return Math.floorMod(next, connections.length); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
logger.info("Closing connections {}", connections.length); | ||
for (AsyncConnection connection : connections) { | ||
IOUtils.closeQuietly(connection, (ioe) -> logger.warn("Failed to close connection", ioe)); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RoundRobinSelector{" + | ||
"connections=" + Arrays.toString(connections) + | ||
'}'; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...ase/src/main/java/com/navercorp/pinpoint/common/hbase/async/SimpleConnectionSelector.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,38 @@ | ||
package com.navercorp.pinpoint.common.hbase.async; | ||
|
||
import com.navercorp.pinpoint.common.util.IOUtils; | ||
import org.apache.hadoop.hbase.client.AsyncConnection; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.io.Closeable; | ||
import java.util.Objects; | ||
|
||
public class SimpleConnectionSelector implements ConnectionSelector, Closeable { | ||
private final Logger logger = LogManager.getLogger(this.getClass()); | ||
|
||
private final AsyncConnection connection; | ||
|
||
public SimpleConnectionSelector(AsyncConnection connection) { | ||
this.connection = Objects.requireNonNull(connection, "connection"); | ||
|
||
} | ||
|
||
|
||
@Override | ||
public AsyncConnection getConnection() { | ||
return connection; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
IOUtils.closeQuietly(connection, (ioe) -> logger.warn("Failed to close connection", ioe)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SimpleConnectionSelector{" + | ||
"connection=" + connection + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.