use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project torodb by torodb.
the class SnapshotMerger method merge.
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
private void merge(MetaDatabase oldDb, MutableMetaCollection newCol, ImmutableMetaCollection oldCol, MetaDocPart newStructure, ImmutableMetaDocPart oldStructure, ImmutableMetaDocPart.Builder parentBuilder, ImmutableMetaIdentifiedDocPartIndex changed, MetaElementState newState) throws UnmergeableException {
ImmutableMetaIdentifiedDocPartIndex byId = oldStructure.getMetaDocPartIndexByIdentifier(changed.getIdentifier());
ImmutableMetaIdentifiedDocPartIndex bySameColumns = oldStructure.streamIndexes().filter(oldDocPartIndex -> oldDocPartIndex.hasSameColumns(changed)).findAny().orElse(null);
switch(newState) {
default:
case NOT_CHANGED:
case NOT_EXISTENT:
throw new AssertionError("A modification was expected, but the new state is " + newState);
case ADDED:
case MODIFIED:
{
Optional<? extends MetaIndex> anyRelatedIndex = newCol.getAnyRelatedIndex(oldCol, newStructure, changed);
if (!anyRelatedIndex.isPresent()) {
throw createUnmergeableExceptionForOrphan(oldDb, oldCol, oldStructure, changed);
}
if (byId == null) {
parentBuilder.put(changed);
return;
}
assert byId != null;
ImmutableMetaIdentifiedDocPartIndex.Builder childBuilder = new ImmutableMetaIdentifiedDocPartIndex.Builder(byId);
Iterator<ImmutableMetaDocPartIndexColumn> indexColumnIterator = changed.iteratorColumns();
while (indexColumnIterator.hasNext()) {
ImmutableMetaDocPartIndexColumn indexColumn = indexColumnIterator.next();
merge(oldDb, oldCol, oldStructure, byId, childBuilder, indexColumn);
}
parentBuilder.put(childBuilder);
break;
}
case REMOVED:
{
Optional<? extends MetaIndex> oldMissedIndex = newCol.getAnyMissedIndex(oldCol, changed);
if (oldMissedIndex.isPresent()) {
throw createUnmergeableExceptionForMissing(oldDb, oldCol, oldStructure, changed, oldMissedIndex.get());
}
if (byId == null || bySameColumns == null) {
/*
* it has been removed on another transaction or created and removed on the current one.
* No change must be done
*/
return;
}
assert byId != null;
assert bySameColumns != null;
/*
* In this case, we can delegate on the backend transaction check. If it thinks everything
* is fine, we can remove the element. If it thinks there is an error, then we have to
* rollback the transaction.
*/
parentBuilder.remove(byId);
}
}
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project graylog2-server by Graylog2.
the class AESTools method encrypt.
@Nullable
public static String encrypt(String plainText, String encryptionKey, String salt) {
try {
@SuppressFBWarnings("CIPHER_INTEGRITY") Cipher cipher = Cipher.getInstance("AES/CBC/ISO10126Padding", "SunJCE");
SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES");
cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(salt.getBytes("UTF-8")));
return Hex.encodeToString(cipher.doFinal(plainText.getBytes("UTF-8")));
} catch (Exception e) {
LOG.error("Could not encrypt value.", e);
}
return null;
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project orientdb by orientechnologies.
the class OLocalHashTable method create.
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
@Override
public void create(OBinarySerializer<K> keySerializer, OBinarySerializer<V> valueSerializer, OType[] keyTypes, boolean nullKeyIsSupported) {
startOperation();
try {
final OAtomicOperation atomicOperation;
try {
atomicOperation = startAtomicOperation(false);
} catch (IOException e) {
throw OException.wrapException(new OIndexException("Error during hash table creation"), e);
}
acquireExclusiveLock();
try {
try {
if (keyTypes != null)
this.keyTypes = Arrays.copyOf(keyTypes, keyTypes.length);
else
this.keyTypes = null;
this.nullKeyIsSupported = nullKeyIsSupported;
this.directory = new OHashTableDirectory(treeStateFileExtension, getName(), getFullName(), durableInNonTxMode, storage);
fileStateId = addFile(atomicOperation, getName() + metadataConfigurationFileExtension);
directory.create();
final OCacheEntry hashStateEntry = addPage(atomicOperation, fileStateId);
pinPage(atomicOperation, hashStateEntry);
hashStateEntry.acquireExclusiveLock();
try {
OHashIndexFileLevelMetadataPage page = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), true);
hashStateEntryIndex = hashStateEntry.getPageIndex();
} finally {
hashStateEntry.releaseExclusiveLock();
releasePage(atomicOperation, hashStateEntry);
}
final String fileName = getFullName();
fileId = addFile(atomicOperation, fileName);
setKeySerializer(keySerializer);
setValueSerializer(valueSerializer);
initHashTreeState(atomicOperation);
if (nullKeyIsSupported)
nullBucketFileId = addFile(atomicOperation, getName() + nullBucketFileExtension);
endAtomicOperation(false, null);
} catch (IOException e) {
endAtomicOperation(true, e);
throw e;
} catch (Exception e) {
endAtomicOperation(true, e);
throw OException.wrapException(new OStorageException("Error during local hash table creation"), e);
}
} catch (IOException e) {
throw OException.wrapException(new OIndexException("Error during local hash table creation"), e);
} finally {
releaseExclusiveLock();
}
} finally {
completeOperation();
}
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project orientdb by orientechnologies.
the class OLocalHashTable20 method initHashTreeState.
@SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
private void initHashTreeState(OAtomicOperation atomicOperation) throws IOException {
for (long pageIndex = 0; pageIndex < MAX_LEVEL_SIZE; pageIndex++) {
final OCacheEntry cacheEntry = loadPageEntry(pageIndex, 0, atomicOperation);
cacheEntry.acquireExclusiveLock();
try {
final OHashIndexBucket<K, V> emptyBucket = new OHashIndexBucket<K, V>(MAX_LEVEL_DEPTH, cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
} finally {
cacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, cacheEntry);
}
}
final long[] rootTree = new long[MAX_LEVEL_SIZE];
for (int i = 0; i < MAX_LEVEL_SIZE; i++) rootTree[i] = createBucketPointer(i, 0);
directory.clear();
directory.addNewNode((byte) 0, (byte) 0, (byte) MAX_LEVEL_DEPTH, rootTree);
OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, hashStateEntryIndex, true);
hashStateEntry.acquireExclusiveLock();
try {
OHashIndexFileLevelMetadataPage metadataPage = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
metadataPage.setBucketsCount(0, MAX_LEVEL_SIZE);
metadataPage.setRecordsCount(0);
} finally {
hashStateEntry.releaseExclusiveLock();
releasePage(atomicOperation, hashStateEntry);
}
}
use of edu.umd.cs.findbugs.annotations.SuppressFBWarnings in project orientdb by orientechnologies.
the class OLogSegment method readRecord.
@SuppressFBWarnings(value = "PZLA_PREFER_ZERO_LENGTH_ARRAYS")
public byte[] readRecord(OLogSequenceNumber lsn, ByteBuffer byteBuffer) throws IOException {
final OPair<OLogSequenceNumber, byte[]> lastRecord = lastReadRecord.get();
if (lastRecord != null && lastRecord.getKey().equals(lsn))
return lastRecord.getValue();
assert lsn.getSegment() == order;
if (lsn.getPosition() >= filledUpTo)
return null;
if (!logCache.isEmpty())
flush();
long pageIndex = lsn.getPosition() / OWALPage.PAGE_SIZE;
byte[] record = null;
int pageOffset = (int) (lsn.getPosition() % OWALPage.PAGE_SIZE);
long pageCount = (filledUpTo + OWALPage.PAGE_SIZE - 1) / OWALPage.PAGE_SIZE;
while (pageIndex < pageCount) {
fileLock.lock();
try {
final RandomAccessFile rndFile = getRndFile();
final FileChannel channel = rndFile.getChannel();
byteBuffer.position(0);
channel.read(byteBuffer, pageIndex * OWALPage.PAGE_SIZE);
} finally {
fileLock.unlock();
}
if (!checkPageIntegrity(byteBuffer))
throw new OWALPageBrokenException("WAL page with index " + pageIndex + " is broken");
OWALPage page = new OWALPage(byteBuffer, false);
byte[] content = page.getRecord(pageOffset);
if (record == null)
record = content;
else {
byte[] oldRecord = record;
record = new byte[record.length + content.length];
System.arraycopy(oldRecord, 0, record, 0, oldRecord.length);
System.arraycopy(content, 0, record, oldRecord.length, record.length - oldRecord.length);
}
if (page.mergeWithNextPage(pageOffset)) {
pageOffset = OWALPage.RECORDS_OFFSET;
pageIndex++;
if (pageIndex >= pageCount)
throw new OWALPageBrokenException("WAL page with index " + pageIndex + " is broken");
} else {
if (page.getFreeSpace() >= OWALPage.MIN_RECORD_SIZE && pageIndex < pageCount - 1)
throw new OWALPageBrokenException("WAL page with index " + pageIndex + " is broken");
break;
}
}
lastReadRecord = new WeakReference<OPair<OLogSequenceNumber, byte[]>>(new OPair<OLogSequenceNumber, byte[]>(lsn, record));
return record;
}
Aggregations