-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
close writer before soft deletion of searchindex #25
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,6 +169,12 @@ class IndexService(ctx: ServiceContext[IndexServiceArgs]) extends Service(ctx) w | |
exit("Idle Timeout") | ||
} | ||
idle = true | ||
case 'close_writer => | ||
debug("Closing writer") | ||
ctx.args.writer.close() | ||
'ok | ||
case 'exit_with_deleted => | ||
exit('deleted) | ||
case 'count_fields => | ||
countFields | ||
case 'delete => | ||
|
@@ -210,7 +216,6 @@ class IndexService(ctx: ServiceContext[IndexServiceArgs]) extends Service(ctx) w | |
} | ||
|
||
override def exit(msg: Any) { | ||
debug("Closed with reason: %.1000s".format(msg)) | ||
try { | ||
reader.close() | ||
} catch { | ||
|
@@ -220,7 +225,12 @@ class IndexService(ctx: ServiceContext[IndexServiceArgs]) extends Service(ctx) w | |
ctx.args.writer.rollback() | ||
} catch { | ||
case e: AlreadyClosedException => 'ignored | ||
case e: IOException => warn("Error while closing writer", e) | ||
case e: IOException => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is the right pattern. rollback() is already a close() (but without the commit), so the fallback to a failed rollback() is just the isLocked/unlock portion (the finally clause). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, let me remove close() line. |
||
val dir = ctx.args.writer.getDirectory | ||
if (IndexWriter.isLocked(dir)) { | ||
IndexWriter.unlock(dir); | ||
} | ||
warn("Error while closing writer", e) | ||
} finally { | ||
super.exit(msg) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,12 @@ package com.cloudant.clouseau | |
import org.apache.lucene.index.Term | ||
import org.apache.lucene.util.BytesRef | ||
import org.apache.lucene.util.NumericUtils | ||
import org.apache.log4j.Logger | ||
import java.io.File | ||
import java.io.IOException | ||
import java.util.Calendar | ||
import java.util.TimeZone | ||
import java.text.SimpleDateFormat | ||
|
||
object Utils { | ||
|
||
|
@@ -29,4 +35,33 @@ object Utils { | |
new BytesRef(string) | ||
} | ||
|
||
def rename(rootDir: File, dbName: String, sig: String) { | ||
val logger = Logger.getLogger("clouseau.utils") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the rootDir here is always the same, so don't pass it in, simply fetch it within this method. This will make it clearer which directory we are renaming. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks that there is no |
||
val srcParentDir = new File(rootDir, dbName) | ||
val sdf = new SimpleDateFormat("yyyyMMdd'.'HHmmss") | ||
sdf.setTimeZone(TimeZone.getTimeZone("UTC")) | ||
val sdfNow = sdf.format(Calendar.getInstance().getTime()) | ||
// move timestamp information in dbName to end of destination path | ||
// for example, from foo.1234567890 to foo.20170912.092828.deleted.1234567890 | ||
val destParentPath = dbName.dropRight(10) + sdfNow + ".deleted." + dbName.takeRight(10) | ||
val destParentDir = new File(rootDir, destParentPath) | ||
logger.info("Renaming '%s' to '%s'".format( | ||
srcParentDir.getAbsolutePath, destParentDir.getAbsolutePath) | ||
) | ||
if (!srcParentDir.isDirectory) { | ||
return | ||
} | ||
if (!destParentDir.exists) { | ||
destParentDir.mkdirs | ||
} | ||
|
||
val srcDir = new File(srcParentDir, sig) | ||
val destDir = new File(destParentDir, sig) | ||
|
||
if (!srcDir.renameTo(destDir)) { | ||
logger.error("Failed to rename directory from '%s' to '%s'".format( | ||
srcDir.getAbsolutePath, destDir.getAbsolutePath)) | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this a different pattern to the one we use in CleanupDbMsg?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for
CleanupDbMsg
, the passed is pure database name while database shardname is passed for SoftDeletePathMsg, likeshards/00000000-ffffffff/foo.1234567890
. So the regexp is different for these two messages.