Skip to content

Commit

Permalink
fixing lock manager bugs
Browse files Browse the repository at this point in the history
-resetting buffers
-truncate file before write,
-logging
  • Loading branch information
hg-ms committed Oct 2, 2024
1 parent 25cbc9e commit 6322ebe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ public default String identifier()
public boolean delete();

public void moveTo(AWritableFile target);



public void truncate(final long newLength);



public static VarString assembleNameAndSize(final VarString vs, final StorageFile file)
{
return vs.add(file.file().identifier() + "[" + file.file().size() + "]");
Expand Down Expand Up @@ -361,6 +363,7 @@ public final synchronized long copyFrom(
}
}

@Override
public synchronized void truncate(final long newLength)
{
this.ensureWritable().truncate(newLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import org.eclipse.serializer.concurrency.XThreads;
import org.eclipse.serializer.memory.XMemory;
import org.eclipse.serializer.util.X;
import org.eclipse.serializer.util.logging.Logging;
import org.eclipse.store.storage.exceptions.StorageException;
import org.eclipse.store.storage.exceptions.StorageExceptionInitialization;
import org.slf4j.Logger;


public interface StorageLockFileManager extends Runnable
Expand Down Expand Up @@ -64,6 +66,8 @@ public static StorageLockFileManager New(

public final class Default implements StorageLockFileManager
{
private final static Logger logger = Logging.getLogger(StorageLockFileManager.class);

///////////////////////////////////////////////////////////////////////////
// instance fields //
////////////////////
Expand Down Expand Up @@ -351,6 +355,8 @@ private boolean lockFileHasContent()

private void initialize()
{
logger.info("initializing lock file manager for storage {}", this.setup.processIdentity());

final StorageLiveFileProvider fileProvider = this.setup.lockFileProvider();
final AFile lockFile = fileProvider.provideLockFile();
this.lockFile = StorageLockFile.New(lockFile);
Expand Down Expand Up @@ -386,6 +392,7 @@ private LockFileData validateExistingLockFileData(final boolean firstAttempt)
if(identifier.equals(existingFiledata.identifier))
{
// database is already owned by "this" process (e.g. crash shorty before), so just continue and reuse.
logger.info("Storage already owned by process!");
return existingFiledata;
}

Expand All @@ -395,13 +402,15 @@ private LockFileData validateExistingLockFileData(final boolean firstAttempt)
* The lock file is no longer updated, meaning the database is not used anymore
* and the lockfile is just a zombie, probably left by a crash.
*/
logger.info("Storage lock file outdated, aquiring storage!");
return existingFiledata;
}

// not owned and not expired
if(firstAttempt)
{
// wait one interval and try a second time
logger.warn("Non expired storage lock found!");
XThreads.sleep(existingFiledata.updateInterval);
return this.validateExistingLockFileData(false);

Expand Down Expand Up @@ -446,12 +455,15 @@ private void writeLockFileData()
}

this.lockFileData.update();



final ArrayView<ByteBuffer> bb = this.setToWriteBuffer(this.lockFileData);

// no need for the writer detour (for now) since it makes no sense to backup lock files.

//don't delete file!
this.lockFile.truncate(0);
this.lockFile.writeBytes(bb);

}

private ArrayView<ByteBuffer> setToWriteBuffer(final LockFileData lockFileData)
Expand All @@ -466,6 +478,7 @@ private ArrayView<ByteBuffer> setToWriteBuffer(final LockFileData lockFileData)
final ArrayView<ByteBuffer> bb = this.ensureWritingBuffer(bytes);

XMemory.copyArrayToAddress(bytes, XMemory.getDirectByteBufferAddress(this.directByteBuffer));
this.directByteBuffer.limit(bytes.length);

return bb;
}
Expand Down

0 comments on commit 6322ebe

Please sign in to comment.