maedhroz commented on code in PR #2540:
URL: https://github.com/apache/cassandra/pull/2540#discussion_r1291503040
##########
src/java/org/apache/cassandra/index/sai/disk/format/IndexDescriptor.java:
##########
@@ -251,36 +257,72 @@ public IndexOutputWriter
openPerIndexOutput(IndexComponent component, IndexConte
return writer;
}
- public FileHandle createPerSSTableFileHandle(IndexComponent indexComponent)
+ public FileHandle createPerSSTableFileHandle(IndexComponent
indexComponent, Throwables.DiscreteAction<?> cleanup)
{
- final File file = fileFor(indexComponent);
+ try
+ {
+ final File file = fileFor(indexComponent);
- if (logger.isTraceEnabled())
+ if (logger.isTraceEnabled())
+ {
+ logger.trace(logMessage("Opening {} file handle for {} ({})"),
+ file,
FBUtilities.prettyPrintMemory(file.length()));
+ }
+
+ return new FileHandle.Builder(file).mmapped(true).complete();
+ }
+ catch (Throwable t)
{
- logger.trace(logMessage("Opening {} file handle for {} ({})"),
- file, FBUtilities.prettyPrintMemory(file.length()));
+ if (cleanup != null)
+ {
+ try
+ {
+ cleanup.perform();
+ }
+ catch (Exception e)
+ {
+ throw Throwables.unchecked(Throwables.merge(t, e));
+ }
+ }
+ throw t;
}
-
- return new FileHandle.Builder(file).mmapped(true).complete();
}
- public FileHandle createPerIndexFileHandle(IndexComponent indexComponent,
IndexContext indexContext)
+ public FileHandle createPerIndexFileHandle(IndexComponent indexComponent,
IndexContext indexContext, Throwables.DiscreteAction<?> cleanup)
{
- final File file = fileFor(indexComponent, indexContext);
+ try
+ {
+ final File file = fileFor(indexComponent, indexContext);
- if (logger.isTraceEnabled())
+ if (logger.isTraceEnabled())
+ {
+ logger.trace(indexContext.logMessage("Opening file handle for
{} ({})"),
+ file,
FBUtilities.prettyPrintMemory(file.length()));
+ }
+
+ return new FileHandle.Builder(file).mmapped(true).complete();
+ }
+ catch (Throwable t)
{
- logger.trace(indexContext.logMessage("Opening file handle for {}
({})"),
- file, FBUtilities.prettyPrintMemory(file.length()));
+ if (cleanup != null)
+ {
+ try
+ {
+ cleanup.perform();
+ }
+ catch (Exception e)
+ {
+ throw Throwables.unchecked(Throwables.merge(t, e));
+ }
+ }
+ throw t;
Review Comment:
nit: I guess you could throw this bit into a helper method so it isn't
repeated in both createX methods.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]