use of java.io.UncheckedIOException in project herddb by diennea.
the class BLink method delete.
// function delete(v: value): boolean;
// var
// n: nodeptr;
// descent: stack;
// begin
// n := locate-leaf(v, writelock, descent); {v € coverset(n) , n write-locked}
// delete := remove-key(v, n); {decisive}
// nornialize(n, descent, 1); unlock(n, writelock)
// end;
public V delete(K v) {
Node<K, V> n;
Deque<ResultCouple<K, V>> descent = new LinkedList<>();
Queue<CriticJob> maintenance = new LinkedList<>();
try {
// v € coverset(n), n write-locked
n = locate_leaf(v, WRITE_LOCK, descent);
} catch (IOException ex) {
throw new UncheckedIOException("failed to delete " + v, ex);
}
V delete;
try {
// decisive
delete = n.remove_key(v);
normalize(n, descent, 1, maintenance);
} catch (IOException ex) {
throw new UncheckedIOException("failed to delete " + v, ex);
} finally {
unlock(n, WRITE_LOCK);
}
if (delete != null) {
size.decrement();
}
handleMainenance(maintenance);
return delete;
}
use of java.io.UncheckedIOException in project herddb by diennea.
the class BLink method scan.
public Stream<Entry<K, V>> scan(K from, K to, boolean toInclusive) {
Node<K, V> n;
Deque<ResultCouple<K, V>> descent = new LinkedList<>();
if (from == null) {
lock_anchor(READ_LOCK);
n = anchor.first;
unlock_anchor(READ_LOCK);
/*
* We have to lock the first node, scan iterator require a read locked node (as produced from
* locate_leaf too)
*/
lock(n, READ_LOCK);
} else {
try {
// v € coverset(n), n read-locked
n = locate_leaf(from, READ_LOCK, descent);
} catch (IOException ex) {
throw new UncheckedIOException("failed to scan from " + from + " to " + to, ex);
}
}
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new ScanIterator(n, from, from != null, to, toInclusive), /* No characteristics */
0), /* No parallel */
false);
}
use of java.io.UncheckedIOException in project herddb by diennea.
the class BLink method scan.
/**
* Supports both from and to empty.
*
* @param from inclusive (if not empty)
* @param to exclusive
* @return
*/
public Stream<Entry<K, V>> scan(K from, K to) {
Node<K, V> n;
Deque<ResultCouple<K, V>> descent = new LinkedList<>();
if (from == null) {
lock_anchor(READ_LOCK);
n = anchor.first;
unlock_anchor(READ_LOCK);
/*
* We have to lock the first node, scan iterator require a read locked node (as produced from
* locate_leaf too)
*/
lock(n, READ_LOCK);
} else {
try {
// v € coverset(n), n read-locked
n = locate_leaf(from, READ_LOCK, descent);
} catch (IOException ex) {
throw new UncheckedIOException("failed to scan from " + from + " to " + to, ex);
}
}
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new ScanIterator(n, from, from != null, to, false), /* No characteristics */
0), /* No parallel */
false);
}
use of java.io.UncheckedIOException in project Bytecoder by mirkosertic.
the class ICUBinary method getRequiredData.
// public methods --------------------------------------------------------
/**
* Loads an ICU binary data file and returns it as a ByteBuffer.
* The buffer contents is normally read-only, but its position etc. can be modified.
*
* @param itemPath Relative ICU data item path, for example "root.res" or "coll/ucadata.icu".
* @return The data as a read-only ByteBuffer.
*/
public static ByteBuffer getRequiredData(String itemPath) {
final Class<ICUBinary> root = ICUBinary.class;
try (InputStream is = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
public InputStream run() {
return root.getResourceAsStream(itemPath);
}
})) {
BufferedInputStream b = new BufferedInputStream(is, 4096);
DataInputStream inputStream = new DataInputStream(b);
byte[] bb = new byte[120000];
int n = inputStream.read(bb);
ByteBuffer bytes = ByteBuffer.wrap(bb, 0, n);
return bytes;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of java.io.UncheckedIOException in project jackrabbit-oak by apache.
the class SegmentWriteQueueTest method testRecoveryMode.
@Test
public void testRecoveryMode() throws IOException, InterruptedException {
Set<UUID> added = Collections.synchronizedSet(new HashSet<>());
Semaphore semaphore = new Semaphore(0);
AtomicBoolean doBreak = new AtomicBoolean(true);
List<Long> writeAttempts = Collections.synchronizedList(new ArrayList<>());
queue = new SegmentWriteQueue((tarEntry, data, offset, size) -> {
writeAttempts.add(System.currentTimeMillis());
try {
semaphore.acquire();
} catch (InterruptedException e) {
}
if (doBreak.get()) {
throw new IOException();
}
added.add(new UUID(tarEntry.getMsb(), tarEntry.getLsb()));
});
for (int i = 0; i < 10; i++) {
queue.addToQueue(tarEntry(i), EMPTY_DATA, 0, 0);
}
semaphore.release(Integer.MAX_VALUE);
Thread.sleep(100);
assertTrue(queue.isBroken());
// the 10th segment is handled by the recovery thread
assertEquals(9, queue.getSize());
writeAttempts.clear();
while (writeAttempts.size() < 5) {
Thread.sleep(100);
}
long lastAttempt = writeAttempts.get(0);
for (int i = 1; i < 5; i++) {
long delay = writeAttempts.get(i) - lastAttempt;
assertTrue("The delay between attempts to persist segment should be larger than 1s. Actual: " + delay, delay >= 1000);
lastAttempt = writeAttempts.get(i);
}
AtomicBoolean addFinished = new AtomicBoolean(false);
new Thread(() -> {
try {
queue.addToQueue(tarEntry(10), EMPTY_DATA, 0, 0);
addFinished.set(true);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}).start();
Thread.sleep(100);
assertFalse("Adding segments should be blocked until the recovery mode is finished", addFinished.get());
doBreak.set(false);
while (queue.isBroken()) {
Thread.sleep(10);
}
assertFalse("Queue shouldn't be broken anymore", queue.isBroken());
while (added.size() < 11) {
Thread.sleep(10);
}
assertEquals("All segments should be consumed", 11, added.size());
for (int i = 0; i < 11; i++) {
assertTrue("All segments should be consumed", added.contains(uuid(i)));
}
int i = writeAttempts.size() - 10;
lastAttempt = writeAttempts.get(i);
for (; i < writeAttempts.size(); i++) {
long delay = writeAttempts.get(i) - lastAttempt;
assertTrue("Segments should be persisted immediately", delay < 1000);
lastAttempt = writeAttempts.get(i);
}
}
Aggregations