use of com.google.common.collect.MapMaker in project DirectMemory by raffaeleguidi.
the class PreliminarBenchmarks method pumpWithOneAllocation.
private void pumpWithOneAllocation(int ops, byte[] payload) {
ConcurrentMap<String, ByteBuffer> test = new MapMaker().concurrencyLevel(4).maximumSize(ops).expireAfterWrite(10, TimeUnit.MINUTES).makeMap();
logger.info(Ram.inMb(ops * payload.length) + " in " + ops + " slices to store");
ByteBuffer bulk = ByteBuffer.allocateDirect(ops * payload.length);
double started = System.currentTimeMillis();
for (int i = 0; i < ops; i++) {
bulk.position(i * payload.length);
final ByteBuffer buf = bulk.duplicate();
buf.put(payload);
test.put("test-" + i, buf);
}
double finished = System.currentTimeMillis();
logger.info("done in " + (finished - started) / 1000 + " seconds");
for (ByteBuffer buf : test.values()) {
buf.clear();
}
}
use of com.google.common.collect.MapMaker in project otter by alibaba.
the class MysqlDialect method initShardColumns.
private void initShardColumns() {
// soft引用设置,避免内存爆了
GenericMapMaker mapMaker = null;
mapMaker = new MapMaker().softValues().evictionListener(new MapEvictionListener<List<String>, Table>() {
public void onEviction(List<String> names, Table table) {
logger.warn("Eviction For Table:" + table);
}
});
this.shardColumns = mapMaker.makeComputingMap(new Function<List<String>, String>() {
public String apply(List<String> names) {
Assert.isTrue(names.size() == 2);
try {
String result = DdlUtils.getShardKeyByDRDS(jdbcTemplate, names.get(0), names.get(0), names.get(1));
if (StringUtils.isEmpty(result)) {
return "";
} else {
return result;
}
} catch (Exception e) {
throw new NestableRuntimeException("find table [" + names.get(0) + "." + names.get(1) + "] error", e);
}
}
});
}
use of com.google.common.collect.MapMaker in project otter by alibaba.
the class DbLoadMergerTest method testMergeWithUpdateKeyOfIUUUU.
/**
* 测试在主键发生变化后的merge操作,Insert/Update/Update/Update/Update
*/
@Test
public void testMergeWithUpdateKeyOfIUUUU() {
Map<RowKey, EventData> mergeMap = new MapMaker().makeMap();
DbLoadMerger.merge(makeInsertEventData(), mergeMap);
DbLoadMerger.merge(makeUpdateEventData(KEY_VALUE, KEY_VALUE_NEW1), mergeMap);
DbLoadMerger.merge(makeUpdateEventData(KEY_VALUE_NEW1, KEY_VALUE_NEW2), mergeMap);
DbLoadMerger.merge(makeUpdateEventData(KEY_VALUE_NEW2, KEY_VALUE_NEW3), mergeMap);
DbLoadMerger.merge(makeUpdateEventData(KEY_VALUE_NEW3, KEY_VALUE_NEW4), mergeMap);
for (Entry<RowKey, EventData> entry : mergeMap.entrySet()) {
RowKey key = entry.getKey();
EventColumn keyColumn = key.getKeys().get(0);
Assert.assertEquals(KEY_VALUE_NEW4, keyColumn.getColumnValue());
Assert.assertEquals(KEY_NAME, keyColumn.getColumnName());
EventData eventData = entry.getValue();
Assert.assertEquals(SCHEMA_NAME, eventData.getSchemaName());
Assert.assertEquals(TABLE_NAME, eventData.getTableName());
Assert.assertEquals(TABLE_ID, eventData.getTableId());
Assert.assertEquals(EventType.INSERT, eventData.getEventType());
// 不存在oldKeys
Assert.assertEquals(eventData.getOldKeys().size(), 0);
}
}
use of com.google.common.collect.MapMaker in project otter by alibaba.
the class DbLoadMergerTest method testMergeWithUpdateKeyOfUU.
/**
* 测试在主键发生变化后的merge操作,Update/Update
*/
@Test
public void testMergeWithUpdateKeyOfUU() {
Map<RowKey, EventData> mergeMap = new MapMaker().makeMap();
DbLoadMerger.merge(makeUpdateEventData(KEY_VALUE, KEY_VALUE_NEW1), mergeMap);
DbLoadMerger.merge(makeUpdateEventData(KEY_VALUE_NEW1, KEY_VALUE_NEW2), mergeMap);
for (Entry<RowKey, EventData> entry : mergeMap.entrySet()) {
RowKey key = entry.getKey();
EventColumn keyColumn = key.getKeys().get(0);
Assert.assertEquals(KEY_VALUE_NEW2, keyColumn.getColumnValue());
Assert.assertEquals(KEY_NAME, keyColumn.getColumnName());
EventData eventData = entry.getValue();
Assert.assertEquals(SCHEMA_NAME, eventData.getSchemaName());
Assert.assertEquals(TABLE_NAME, eventData.getTableName());
Assert.assertEquals(TABLE_ID, eventData.getTableId());
Assert.assertEquals(EventType.UPDATE, eventData.getEventType());
List<EventColumn> oldKeys = eventData.getOldKeys();
List<EventColumn> keys = eventData.getKeys();
Assert.assertNotSame(oldKeys, keys);
}
}
use of com.google.common.collect.MapMaker in project otter by alibaba.
the class DbLoadMergerTest method testMergeWithSameKeyOfIUDI.
/**
* 测试insert+update+delete+insert
*/
@Test
public void testMergeWithSameKeyOfIUDI() {
Map<RowKey, EventData> mergeMap = new MapMaker().makeMap();
DbLoadMerger.merge(makeInsertEventData(), mergeMap);
DbLoadMerger.merge(makeUpdateEventData(), mergeMap);
DbLoadMerger.merge(makeDeleteEventData(), mergeMap);
DbLoadMerger.merge(makeInsertEventData(), mergeMap);
for (Entry<RowKey, EventData> entry : mergeMap.entrySet()) {
RowKey key = entry.getKey();
EventColumn keyColumn = key.getKeys().get(0);
Assert.assertEquals(KEY_VALUE, keyColumn.getColumnValue());
Assert.assertEquals(KEY_NAME, keyColumn.getColumnName());
EventData eventData = entry.getValue();
Assert.assertEquals(SCHEMA_NAME, eventData.getSchemaName());
Assert.assertEquals(TABLE_NAME, eventData.getTableName());
Assert.assertEquals(TABLE_ID, eventData.getTableId());
Assert.assertEquals(EventType.INSERT, eventData.getEventType());
// 不存在oldKeys
Assert.assertEquals(eventData.getOldKeys().size(), 0);
List<EventColumn> columns = eventData.getColumns();
Assert.assertEquals(2, columns.size());
}
}
Aggregations