switch (userDurability) { case "sync": cfg.setDurability(Durability.SYNC); break; case "flush": cfg.setDurability(Durability.FLUSH); break; case "none": cfg.setDurability(Durability.NONE); break; case "log": cfg.setDurability(Durability.NONE); break; default:
public BatchWriterConfig getBatchWriterConfig() { ensureOpen(); if (batchWriterConfig == null) { Properties props = info.getProperties(); batchWriterConfig = new BatchWriterConfig(); Long maxMemory = ClientProperty.BATCH_WRITER_MEMORY_MAX.getBytes(props); if (maxMemory != null) { batchWriterConfig.setMaxMemory(maxMemory); } Long maxLatency = ClientProperty.BATCH_WRITER_LATENCY_MAX.getTimeInMillis(props); if (maxLatency != null) { batchWriterConfig.setMaxLatency(maxLatency, TimeUnit.SECONDS); } Long timeout = ClientProperty.BATCH_WRITER_TIMEOUT_MAX.getTimeInMillis(props); if (timeout != null) { batchWriterConfig.setTimeout(timeout, TimeUnit.SECONDS); } String durability = ClientProperty.BATCH_WRITER_DURABILITY.getValue(props); if (!durability.isEmpty()) { batchWriterConfig.setDurability(Durability.valueOf(durability.toUpperCase())); } } return batchWriterConfig; }
switch (userDurability) { case "sync": cfg.setDurability(Durability.SYNC); break; case "flush": cfg.setDurability(Durability.FLUSH); break; case "none": cfg.setDurability(Durability.NONE); break; case "log": cfg.setDurability(Durability.NONE); break; default:
/** * Gets the {@link BatchWriterConfig} settings that were stored with ClientInfo */ public static BatchWriterConfig getBatchWriterOptions(Class<?> implementingClass, Configuration conf) { BatchWriterConfig bwConfig = new BatchWriterConfig(); Properties props = getClientProperties(implementingClass, conf); String property = props.getProperty(BATCH_WRITER_DURABILITY.getKey()); if (property != null) bwConfig.setDurability(DurabilityImpl.fromString(property)); Long value = BATCH_WRITER_LATENCY_MAX.getTimeInMillis(props); if (value != null) bwConfig.setMaxLatency(value, TimeUnit.MILLISECONDS); value = BATCH_WRITER_MEMORY_MAX.getBytes(props); if (value != null) bwConfig.setMaxMemory(value); value = BATCH_WRITER_TIMEOUT_MAX.getTimeInMillis(props); if (value != null) bwConfig.setTimeout(value, TimeUnit.MILLISECONDS); Integer intValue = BATCH_WRITER_THREADS_MAX.getInteger(props); if (intValue != null) bwConfig.setMaxWriteThreads(intValue); return bwConfig; }
BatchWriterPlusProblem getWriter(ByteBuffer login, String tableName, WriterOptions opts) throws Exception { BatchWriterConfig cfg = new BatchWriterConfig(); if (opts != null) { if (opts.maxMemory != 0) cfg.setMaxMemory(opts.maxMemory); if (opts.threads != 0) cfg.setMaxWriteThreads(opts.threads); if (opts.timeoutMs != 0) cfg.setTimeout(opts.timeoutMs, TimeUnit.MILLISECONDS); if (opts.latencyMs != 0) cfg.setMaxLatency(opts.latencyMs, TimeUnit.MILLISECONDS); if (opts.isSetDurability() && opts.durability != null) { cfg.setDurability(getDurability(opts.getDurability())); } } BatchWriterPlusProblem result = new BatchWriterPlusProblem(); result.writer = getConnector(login).createBatchWriter(tableName, cfg); return result; }
@Test(timeout = 3 * 60 * 1000) public void durableTableLosesNonDurableWrites() throws Exception { Connector c = getConnector(); String tableName = getUniqueNames(1)[0]; // table default is durable writes c.tableOperations().create(tableName); c.tableOperations().setProperty(tableName, Property.TABLE_DURABILITY.getKey(), "sync"); // write with no durability BatchWriterConfig cfg = new BatchWriterConfig(); cfg.setDurability(Durability.NONE); writeSome(tableName, 10, cfg); // verify writes are lost on restart restartTServer(); assertTrue(10 > count(tableName)); }
@Test(timeout = 3 * 60 * 1000) public void nondurableTableHasDurableWrites() throws Exception { Connector c = getConnector(); String tableName = getUniqueNames(1)[0]; // table default has no durability c.tableOperations().create(tableName); c.tableOperations().setProperty(tableName, Property.TABLE_DURABILITY.getKey(), "none"); // send durable writes BatchWriterConfig cfg = new BatchWriterConfig(); cfg.setDurability(Durability.SYNC); writeSome(tableName, 10, cfg); assertEquals(10, count(tableName)); // verify writes servive restart restartTServer(); assertEquals(10, count(tableName)); }