use of org.apache.geode.internal.cache.persistence.BytesAndBits in project geode by apache.
the class DiskStoreImpl method get.
/**
* Returns the value of the key/value pair with the given diskId. Updates all of the necessary
* {@linkplain DiskRegionStats statistics}
*
*/
Object get(DiskRegion dr, DiskId id) {
acquireReadLock(dr);
try {
int count = 0;
RuntimeException ex = null;
while (count < 3) {
// retry at most 3 times
BytesAndBits bb = null;
try {
if (dr.isRegionClosed()) {
throw new RegionDestroyedException(LocalizedStrings.DiskRegion_THE_DISKREGION_HAS_BEEN_CLOSED_OR_DESTROYED.toLocalizedString(), dr.getName());
}
if (dr.didClearCountChange()) {
return Token.REMOVED_PHASE1;
}
bb = getBytesAndBitsWithoutLock(dr, id, true, /* fault -in */
false);
if (bb == CLEAR_BB) {
return Token.REMOVED_PHASE1;
}
return convertBytesAndBitsIntoObject(bb);
} catch (IllegalArgumentException e) {
count++;
if (logger.isDebugEnabled()) {
logger.debug("DiskRegion: Tried {}, getBytesAndBitsWithoutLock returns wrong byte array: {}", count, Arrays.toString(bb.getBytes()));
}
ex = e;
}
}
// while
if (logger.isDebugEnabled()) {
logger.debug("Retried 3 times, getting entry from DiskRegion still failed. It must be Oplog file corruption due to HA");
}
throw ex;
} finally {
releaseReadLock(dr);
}
}
use of org.apache.geode.internal.cache.persistence.BytesAndBits in project geode by apache.
the class OverflowOplog method attemptGet.
private BytesAndBits attemptGet(DiskRegionView dr, long offsetInOplog, int valueLength, byte userBits) throws IOException {
synchronized (this.crf) {
assert offsetInOplog >= 0;
RandomAccessFile myRAF = this.crf.raf;
BytesAndBits bb = null;
long writePosition = 0;
if (!this.doneAppending) {
writePosition = myRAF.getFilePointer();
bb = attemptWriteBufferGet(writePosition, offsetInOplog, valueLength, userBits);
if (bb == null) {
if (/*
* !getParent().isSync() since compactor groups writes &&
*/
(offsetInOplog + valueLength) > this.crf.bytesFlushed && !this.closed) {
// fix for bug 41205
flushAll();
writePosition = myRAF.getFilePointer();
}
}
}
if (bb == null) {
myRAF.seek(offsetInOplog);
try {
this.stats.incOplogSeeks();
byte[] valueBytes = new byte[valueLength];
myRAF.readFully(valueBytes);
// if (EntryBits.isSerialized(userBits)) {
// try {
// org.apache.geode.internal.util.BlobHelper.deserializeBlob(valueBytes);
// } catch (IOException ex) {
// throw new RuntimeException("DEBUG readPos=" + readPosition + " len=" + valueLength +
// "doneApp=" + doneAppending + " userBits=" + userBits, ex);
// } catch (ClassNotFoundException ex2) {
// throw new RuntimeException(ex2);
// }
// }
this.stats.incOplogReads();
bb = new BytesAndBits(valueBytes, userBits);
} finally {
// if this oplog is no longer being appended to then don't waste disk io
if (!this.doneAppending) {
myRAF.seek(writePosition);
this.stats.incOplogSeeks();
}
}
}
return bb;
}
// sync
}
use of org.apache.geode.internal.cache.persistence.BytesAndBits in project geode by apache.
the class OverflowOplog method basicGet.
/**
* Extracts the Value byte array & UserBit from the OpLog
*
* @param offsetInOplog The starting position from which to read the data in the opLog
* @param bitOnly boolean indicating whether the value needs to be extracted along with the
* UserBit or not.
* @param valueLength The length of the byte array which represents the value
* @param userBits The userBits of the value.
* @return BytesAndBits object which wraps the extracted value & user bit
*/
private BytesAndBits basicGet(DiskRegionView dr, long offsetInOplog, boolean bitOnly, int valueLength, byte userBits) {
BytesAndBits bb = null;
if (EntryBits.isAnyInvalid(userBits) || EntryBits.isTombstone(userBits) || bitOnly || valueLength == 0) {
if (EntryBits.isInvalid(userBits)) {
bb = new BytesAndBits(DiskEntry.INVALID_BYTES, userBits);
} else if (EntryBits.isTombstone(userBits)) {
bb = new BytesAndBits(DiskEntry.TOMBSTONE_BYTES, userBits);
} else {
bb = new BytesAndBits(DiskEntry.LOCAL_INVALID_BYTES, userBits);
}
} else {
if (offsetInOplog == -1)
return null;
try {
for (; ; ) {
dr.getCancelCriterion().checkCancelInProgress(null);
boolean interrupted = Thread.interrupted();
try {
bb = attemptGet(dr, offsetInOplog, valueLength, userBits);
break;
} catch (InterruptedIOException ignore) {
// bug 39756
// ignore, we'll clear and retry.
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
// for
} catch (IOException ex) {
throw new DiskAccessException(LocalizedStrings.Oplog_FAILED_READING_FROM_0_OPLOGID_1_OFFSET_BEING_READ_2_CURRENT_OPLOG_SIZE_3_ACTUAL_FILE_SIZE_4_IS_ASYNCH_MODE_5_IS_ASYNCH_WRITER_ALIVE_6.toLocalizedString(this.diskFile.getPath(), (long) this.oplogId, offsetInOplog, this.crf.currSize, this.crf.bytesFlushed, !dr.isSync(), false), ex, dr.getName());
} catch (IllegalStateException ex) {
checkClosed();
throw ex;
}
}
return bb;
}
use of org.apache.geode.internal.cache.persistence.BytesAndBits in project geode by apache.
the class OverflowOplog method attemptWriteBufferGet.
private BytesAndBits attemptWriteBufferGet(long writePosition, long readPosition, int valueLength, byte userBits) {
BytesAndBits bb = null;
ByteBuffer writeBuf = this.crf.writeBuf;
int curWriteBufPos = writeBuf.position();
if (writePosition <= readPosition && (writePosition + curWriteBufPos) >= (readPosition + valueLength)) {
int bufOffset = (int) (readPosition - writePosition);
byte[] valueBytes = new byte[valueLength];
int oldLimit = writeBuf.limit();
writeBuf.limit(curWriteBufPos);
writeBuf.position(bufOffset);
writeBuf.get(valueBytes);
writeBuf.position(curWriteBufPos);
writeBuf.limit(oldLimit);
bb = new BytesAndBits(valueBytes, userBits);
}
return bb;
}
use of org.apache.geode.internal.cache.persistence.BytesAndBits in project geode by apache.
the class DiskStoreImpl method getNoBuffer.
/**
* Asif: THIS SHOULD ONLY BE USED FOR TESTING PURPOSES AS IT IS NOT THREAD SAFE
*
* Returns the object stored on disk with the given id. This method is used for testing purposes
* only. As such, it bypasses the buffer and goes directly to the disk. This is not a thread safe
* function , in the sense, it is possible that by the time the OpLog is queried , data might move
* HTree with the oplog being destroyed
*
* @return null if entry has nothing stored on disk (id == INVALID_ID)
* @throws IllegalArgumentException If {@code id} is less than zero, no action is taken.
*/
public Object getNoBuffer(DiskRegion dr, DiskId id) {
BytesAndBits bb = null;
acquireReadLock(dr);
try {
long opId = id.getOplogId();
if (opId != -1) {
OplogSet oplogSet = getOplogSet(dr);
bb = oplogSet.getChild(opId).getNoBuffer(dr, id);
return convertBytesAndBitsIntoObject(bb);
} else {
return null;
}
} finally {
releaseReadLock(dr);
}
}
Aggregations