optimize translog sync to not happen if there is no need for it
This commit is contained in:
parent
3b2c186503
commit
03dc146928
|
@ -38,6 +38,8 @@ public class FsTranslogFile {
|
||||||
private final AtomicLong lastPosition = new AtomicLong(0);
|
private final AtomicLong lastPosition = new AtomicLong(0);
|
||||||
private final AtomicLong lastWrittenPosition = new AtomicLong(0);
|
private final AtomicLong lastWrittenPosition = new AtomicLong(0);
|
||||||
|
|
||||||
|
private volatile long lastSyncPosition = 0;
|
||||||
|
|
||||||
public FsTranslogFile(ShardId shardId, long id, RafReference raf) throws IOException {
|
public FsTranslogFile(ShardId shardId, long id, RafReference raf) throws IOException {
|
||||||
this.shardId = shardId;
|
this.shardId = shardId;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -84,6 +86,12 @@ public class FsTranslogFile {
|
||||||
|
|
||||||
public void sync() {
|
public void sync() {
|
||||||
try {
|
try {
|
||||||
|
// check if we really need to sync here...
|
||||||
|
long last = lastWrittenPosition.get();
|
||||||
|
if (last == lastSyncPosition) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastSyncPosition = last;
|
||||||
raf.channel().force(false);
|
raf.channel().force(false);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignore
|
// ignore
|
||||||
|
|
Loading…
Reference in New Issue