use of java.util.concurrent.ConcurrentHashMap in project groovy by apache.
the class ManagedConcurrentValueMapStressTest method size.
private static int size(ManagedConcurrentValueMap<String, Object> map) {
MetaClass metaClass = InvokerHelper.getMetaClass(map);
ConcurrentHashMap<String, Object> internalMap = (ConcurrentHashMap<String, Object>) metaClass.getProperty(map, "internalMap");
return internalMap.size();
}
use of java.util.concurrent.ConcurrentHashMap in project Mycat-Server by MyCATApache.
the class ShareRowOutPutDataHandler method onRowData.
@Override
public boolean onRowData(String dataNode, byte[] rowData) {
RowDataPacket rowDataPkgold = ResultSetUtil.parseRowData(rowData, bfields);
//拷贝一份batchRows
Map<String, byte[]> batchRowsCopy = new ConcurrentHashMap<String, byte[]>();
batchRowsCopy.putAll(arows);
// 获取Id字段,
String id = ByteUtil.getString(rowDataPkgold.fieldValues.get(joinR));
// 查找ID对应的A表的记录
//arows.remove(id);
byte[] arow = getRow(batchRowsCopy, id, joinL);
// byte[] arow = getRow(id,joinL);//arows.remove(id);
while (arow != null) {
//ctx.getAllFields());
RowDataPacket rowDataPkg = ResultSetUtil.parseRowData(arow, afields);
for (int i = 1; i < rowDataPkgold.fieldCount; i++) {
// 设置b.name 字段
byte[] bname = rowDataPkgold.fieldValues.get(i);
rowDataPkg.add(bname);
rowDataPkg.addFieldCount(1);
}
//RowData(rowDataPkg);
ctx.writeRow(rowDataPkg);
arow = getRow(batchRowsCopy, id, joinL);
// arow = getRow(id,joinL);
}
return false;
}
use of java.util.concurrent.ConcurrentHashMap in project Mycat-Server by MyCATApache.
the class MySQLTableStructureDetector method run.
@Override
public void run() {
for (SchemaConfig schema : MycatServer.getInstance().getConfig().getSchemas().values()) {
for (TableConfig table : schema.getTables().values()) {
for (String dataNode : table.getDataNodes()) {
try {
table.getReentrantReadWriteLock().writeLock().lock();
ConcurrentHashMap<String, List<String>> map = new ConcurrentHashMap<>();
table.setDataNodeTableStructureSQLMap(map);
} finally {
table.getReentrantReadWriteLock().writeLock().unlock();
}
OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(MYSQL_SHOW_CREATE_TABLE_COLMS, new MySQLTableStructureListener(dataNode, table));
resultHandler.setMark("Table Structure");
PhysicalDBNode dn = MycatServer.getInstance().getConfig().getDataNodes().get(dataNode);
SQLJob sqlJob = new SQLJob(sqlPrefix + table.getName(), dn.getDatabase(), resultHandler, dn.getDbPool().getSource());
sqlJob.run();
}
}
}
}
use of java.util.concurrent.ConcurrentHashMap in project Mycat-Server by MyCATApache.
the class ShowDirectMemory method showDirectMemoryTotal.
public static void showDirectMemoryTotal(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = totalHeader.write(buffer, c, true);
// write fields
for (FieldPacket field : totalFields) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = totalEof.write(buffer, c, true);
// write rows
byte packetId = totalEof.packetId;
int useOffHeapForMerge = MycatServer.getInstance().getConfig().getSystem().getUseOffHeapForMerge();
ConcurrentHashMap<Long, Long> networkbufferpool = MycatServer.getInstance().getBufferPool().getNetDirectMemoryUsage();
RowDataPacket row = new RowDataPacket(TOTAL_FIELD_COUNT);
long usedforMerge = 0;
long usedforNetworkd = 0;
try {
/**
* 通过-XX:MaxDirectMemorySize=2048m设置的值
*/
row.add(JavaUtils.bytesToString2(Platform.getMaxDirectMemory()).getBytes(c.getCharset()));
if (useOffHeapForMerge == 1) {
/**
* 结果集合并时,总共消耗的DirectMemory内存
*/
ConcurrentHashMap<Long, Long> concurrentHashMap = MycatServer.getInstance().getMyCatMemory().getResultMergeMemoryManager().getDirectMemorUsage();
for (Map.Entry<Long, Long> entry : concurrentHashMap.entrySet()) {
usedforMerge += entry.getValue();
}
}
/**
* 网络packet处理,在buffer pool 已经使用DirectMemory内存
*/
for (Map.Entry<Long, Long> entry : networkbufferpool.entrySet()) {
usedforNetworkd += entry.getValue();
}
row.add(JavaUtils.bytesToString2(usedforMerge + usedforNetworkd).getBytes(c.getCharset()));
long totalAvailable = 0;
if (useOffHeapForMerge == 1) {
/**
* 设置使用off-heap内存处理结果集时,防止客户把MaxDirectMemorySize设置到物理内存的极限。
* Mycat能使用的DirectMemory是MaxDirectMemorySize*DIRECT_SAFETY_FRACTION大小,
* DIRECT_SAFETY_FRACTION为安全系数,为OS,Heap预留空间,避免因大结果集造成系统物理内存被耗尽!
*/
totalAvailable = (long) (Platform.getMaxDirectMemory() * MyCatMemory.DIRECT_SAFETY_FRACTION);
} else {
totalAvailable = Platform.getMaxDirectMemory();
}
row.add(JavaUtils.bytesToString2(totalAvailable - usedforMerge - usedforNetworkd).getBytes(c.getCharset()));
if (useOffHeapForMerge == 1) {
/**
* 输出安全系统DIRECT_SAFETY_FRACTION
*/
row.add(("" + MyCatMemory.DIRECT_SAFETY_FRACTION).getBytes(c.getCharset()));
} else {
row.add(("1.0").getBytes(c.getCharset()));
}
long resevedForOs = 0;
if (useOffHeapForMerge == 1) {
/**
* 预留OS系统部分内存!!!
*/
resevedForOs = (long) ((1 - MyCatMemory.DIRECT_SAFETY_FRACTION) * (Platform.getMaxDirectMemory() - 2 * MycatServer.getInstance().getTotalNetWorkBufferSize()));
}
row.add(resevedForOs > 0 ? JavaUtils.bytesToString2(resevedForOs).getBytes(c.getCharset()) : "0".getBytes(c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of java.util.concurrent.ConcurrentHashMap in project DataX by alibaba.
the class ProcessInnerCollectorTest method testCollectFromTaskGroup.
@Test
public void testCollectFromTaskGroup() throws NoSuchFieldException, IllegalAccessException {
Integer taskGroupId_1 = 1;
Integer taskGroupId_2 = 2;
Communication communication_1 = new Communication();
communication_1.setLongCounter("totalBytes", 888);
Communication communication_2 = new Communication();
communication_2.setLongCounter("totalBytes", 112);
ConcurrentHashMap<Integer, Communication> taskGroupCommunicationMap = new ConcurrentHashMap<Integer, Communication>();
taskGroupCommunicationMap.put(taskGroupId_1, communication_1);
taskGroupCommunicationMap.put(taskGroupId_2, communication_2);
ReflectUtil.setField(new LocalTGCommunicationManager(), "taskGroupCommunicationMap", taskGroupCommunicationMap);
ProcessInnerCollector processInnerCollector = new ProcessInnerCollector(0L);
Communication comm = processInnerCollector.collectFromTaskGroup();
Assert.assertTrue(comm.getLongCounter("totalBytes") == 1000);
System.out.println(comm);
}
Aggregations