use of org.apache.lucene.store.AlreadyClosedException in project crate by crate.
the class StreamInput method readException.
@SuppressWarnings("unchecked")
public <T extends Exception> T readException() throws IOException {
if (readBoolean()) {
int key = readVInt();
switch(key) {
case 0:
final int ord = readVInt();
if (ord == 59) {
final ElasticsearchException ex = new ElasticsearchException(this);
final boolean isExecutorShutdown = readBoolean();
return (T) new EsRejectedExecutionException(ex.getMessage(), isExecutorShutdown);
}
return (T) ElasticsearchException.readException(this, ord);
case 1:
String msg1 = readOptionalString();
String resource1 = readOptionalString();
return (T) readStackTrace(new CorruptIndexException(msg1, resource1, readException()), this);
case 2:
String resource2 = readOptionalString();
int version2 = readInt();
int minVersion2 = readInt();
int maxVersion2 = readInt();
return (T) readStackTrace(new IndexFormatTooNewException(resource2, version2, minVersion2, maxVersion2), this);
case 3:
String resource3 = readOptionalString();
if (readBoolean()) {
int version3 = readInt();
int minVersion3 = readInt();
int maxVersion3 = readInt();
return (T) readStackTrace(new IndexFormatTooOldException(resource3, version3, minVersion3, maxVersion3), this);
} else {
String version3 = readOptionalString();
return (T) readStackTrace(new IndexFormatTooOldException(resource3, version3), this);
}
case 4:
return (T) readStackTrace(new NullPointerException(readOptionalString()), this);
case 5:
return (T) readStackTrace(new NumberFormatException(readOptionalString()), this);
case 6:
return (T) readStackTrace(new IllegalArgumentException(readOptionalString(), readException()), this);
case 7:
return (T) readStackTrace(new AlreadyClosedException(readOptionalString(), readException()), this);
case 8:
return (T) readStackTrace(new EOFException(readOptionalString()), this);
case 9:
return (T) readStackTrace(new SecurityException(readOptionalString(), readException()), this);
case 10:
return (T) readStackTrace(new StringIndexOutOfBoundsException(readOptionalString()), this);
case 11:
return (T) readStackTrace(new ArrayIndexOutOfBoundsException(readOptionalString()), this);
case 12:
return (T) readStackTrace(new FileNotFoundException(readOptionalString()), this);
case 13:
final int subclass = readVInt();
final String file = readOptionalString();
final String other = readOptionalString();
final String reason = readOptionalString();
// skip the msg - it's composed from file, other and reason
readOptionalString();
final Exception exception;
switch(subclass) {
case 0:
exception = new NoSuchFileException(file, other, reason);
break;
case 1:
exception = new NotDirectoryException(file);
break;
case 2:
exception = new DirectoryNotEmptyException(file);
break;
case 3:
exception = new AtomicMoveNotSupportedException(file, other, reason);
break;
case 4:
exception = new FileAlreadyExistsException(file, other, reason);
break;
case 5:
exception = new AccessDeniedException(file, other, reason);
break;
case 6:
exception = new FileSystemLoopException(file);
break;
case 7:
exception = new FileSystemException(file, other, reason);
break;
default:
throw new IllegalStateException("unknown FileSystemException with index " + subclass);
}
return (T) readStackTrace(exception, this);
case 14:
return (T) readStackTrace(new IllegalStateException(readOptionalString(), readException()), this);
case 15:
return (T) readStackTrace(new LockObtainFailedException(readOptionalString(), readException()), this);
case 16:
return (T) readStackTrace(new InterruptedException(readOptionalString()), this);
case 17:
return (T) readStackTrace(new IOException(readOptionalString(), readException()), this);
case 18:
final boolean isExecutorShutdown = readBoolean();
return (T) readStackTrace(new EsRejectedExecutionException(readOptionalString(), isExecutorShutdown), this);
case 19:
return (T) readStackTrace(new UncheckedIOException(readOptionalString(), readException()), this);
default:
throw new IOException("no such exception for id: " + key);
}
}
return null;
}
use of org.apache.lucene.store.AlreadyClosedException in project crate by crate.
the class SysShardsExpressionsTest method testMinLuceneVersion.
@Test
public void testMinLuceneVersion() throws Exception {
Reference refInfo = refInfo("sys.shards.min_lucene_version", DataTypes.STRING, RowGranularity.SHARD);
NestableInput<String> shardExpression = (NestableInput<String>) resolver.getImplementation(refInfo);
assertEquals(Version.LATEST.toString(), shardExpression.value());
doThrow(new AlreadyClosedException("Already closed")).when(indexShard).minimumCompatibleVersion();
shardExpression = (NestableInput<String>) resolver.getImplementation(refInfo);
assertThat(shardExpression.value(), nullValue());
}
use of org.apache.lucene.store.AlreadyClosedException in project crate by crate.
the class SysShardsExpressionsTest method testShardSizeExpressionWhenIndexShardHasBeenClosed.
@Test
public void testShardSizeExpressionWhenIndexShardHasBeenClosed() {
IndexShard mock = mockIndexShard();
when(mock.storeStats()).thenThrow(new AlreadyClosedException("shard already closed"));
ShardReferenceResolver resolver = new ShardReferenceResolver(schemas, new ShardRowContext(mock, clusterService));
Reference refInfo = refInfo("sys.shards.size", DataTypes.LONG, RowGranularity.SHARD);
NestableInput<Long> shardSizeExpression = (NestableInput<Long>) resolver.getImplementation(refInfo);
assertThat(shardSizeExpression.value(), is(0L));
}
use of org.apache.lucene.store.AlreadyClosedException in project elasticsearch by elastic.
the class Translog method add.
/**
* Adds an operation to the transaction log.
*
* @param operation the operation to add
* @return the location of the operation in the translog
* @throws IOException if adding the operation to the translog resulted in an I/O exception
*/
public Location add(final Operation operation) throws IOException {
final ReleasableBytesStreamOutput out = new ReleasableBytesStreamOutput(bigArrays);
try {
final BufferedChecksumStreamOutput checksumStreamOutput = new BufferedChecksumStreamOutput(out);
final long start = out.position();
out.skip(Integer.BYTES);
writeOperationNoSize(checksumStreamOutput, operation);
final long end = out.position();
final int operationSize = (int) (end - Integer.BYTES - start);
out.seek(start);
out.writeInt(operationSize);
out.seek(end);
final ReleasablePagedBytesReference bytes = out.bytes();
try (ReleasableLock ignored = readLock.acquire()) {
ensureOpen();
return current.add(bytes, operation.seqNo());
}
} catch (final AlreadyClosedException | IOException ex) {
try {
closeOnTragicEvent(ex);
} catch (final Exception inner) {
ex.addSuppressed(inner);
}
throw ex;
} catch (final Exception e) {
try {
closeOnTragicEvent(e);
} catch (final Exception inner) {
e.addSuppressed(inner);
}
throw new TranslogException(shardId, "Failed to write operation [" + operation + "]", e);
} finally {
Releasables.close(out.bytes());
}
}
use of org.apache.lucene.store.AlreadyClosedException in project elasticsearch by elastic.
the class StreamOutput method writeException.
public void writeException(Throwable throwable) throws IOException {
if (throwable == null) {
writeBoolean(false);
} else {
writeBoolean(true);
boolean writeCause = true;
boolean writeMessage = true;
if (throwable instanceof CorruptIndexException) {
writeVInt(1);
writeOptionalString(((CorruptIndexException) throwable).getOriginalMessage());
writeOptionalString(((CorruptIndexException) throwable).getResourceDescription());
writeMessage = false;
} else if (throwable instanceof IndexFormatTooNewException) {
writeVInt(2);
writeOptionalString(((IndexFormatTooNewException) throwable).getResourceDescription());
writeInt(((IndexFormatTooNewException) throwable).getVersion());
writeInt(((IndexFormatTooNewException) throwable).getMinVersion());
writeInt(((IndexFormatTooNewException) throwable).getMaxVersion());
writeMessage = false;
writeCause = false;
} else if (throwable instanceof IndexFormatTooOldException) {
writeVInt(3);
IndexFormatTooOldException t = (IndexFormatTooOldException) throwable;
writeOptionalString(t.getResourceDescription());
if (t.getVersion() == null) {
writeBoolean(false);
writeOptionalString(t.getReason());
} else {
writeBoolean(true);
writeInt(t.getVersion());
writeInt(t.getMinVersion());
writeInt(t.getMaxVersion());
}
writeMessage = false;
writeCause = false;
} else if (throwable instanceof NullPointerException) {
writeVInt(4);
writeCause = false;
} else if (throwable instanceof NumberFormatException) {
writeVInt(5);
writeCause = false;
} else if (throwable instanceof IllegalArgumentException) {
writeVInt(6);
} else if (throwable instanceof AlreadyClosedException) {
writeVInt(7);
} else if (throwable instanceof EOFException) {
writeVInt(8);
writeCause = false;
} else if (throwable instanceof SecurityException) {
writeVInt(9);
} else if (throwable instanceof StringIndexOutOfBoundsException) {
writeVInt(10);
writeCause = false;
} else if (throwable instanceof ArrayIndexOutOfBoundsException) {
writeVInt(11);
writeCause = false;
} else if (throwable instanceof FileNotFoundException) {
writeVInt(12);
writeCause = false;
} else if (throwable instanceof FileSystemException) {
writeVInt(13);
if (throwable instanceof NoSuchFileException) {
writeVInt(0);
} else if (throwable instanceof NotDirectoryException) {
writeVInt(1);
} else if (throwable instanceof DirectoryNotEmptyException) {
writeVInt(2);
} else if (throwable instanceof AtomicMoveNotSupportedException) {
writeVInt(3);
} else if (throwable instanceof FileAlreadyExistsException) {
writeVInt(4);
} else if (throwable instanceof AccessDeniedException) {
writeVInt(5);
} else if (throwable instanceof FileSystemLoopException) {
writeVInt(6);
} else {
writeVInt(7);
}
writeOptionalString(((FileSystemException) throwable).getFile());
writeOptionalString(((FileSystemException) throwable).getOtherFile());
writeOptionalString(((FileSystemException) throwable).getReason());
writeCause = false;
} else if (throwable instanceof IllegalStateException) {
writeVInt(14);
} else if (throwable instanceof LockObtainFailedException) {
writeVInt(15);
} else if (throwable instanceof InterruptedException) {
writeVInt(16);
writeCause = false;
} else if (throwable instanceof IOException) {
writeVInt(17);
} else {
ElasticsearchException ex;
if (throwable instanceof ElasticsearchException && ElasticsearchException.isRegistered(throwable.getClass(), version)) {
ex = (ElasticsearchException) throwable;
} else {
ex = new NotSerializableExceptionWrapper(throwable);
}
writeVInt(0);
writeVInt(ElasticsearchException.getId(ex.getClass()));
ex.writeTo(this);
return;
}
if (writeMessage) {
writeOptionalString(throwable.getMessage());
}
if (writeCause) {
writeException(throwable.getCause());
}
ElasticsearchException.writeStackTraces(throwable, this);
}
}
Aggregations