mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-29 04:57:48 +01:00
Compare commits
3 Commits
eaa413e200
...
4f5f347b3c
| Author | SHA1 | Date | |
|---|---|---|---|
| 4f5f347b3c | |||
| bd5395e03f | |||
| f56f564e8b |
@@ -72,26 +72,6 @@
|
|||||||
<artifactId>quarkus-junit5</artifactId>
|
<artifactId>quarkus-junit5</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.SerCeMan</groupId>
|
|
||||||
<artifactId>jnr-fuse</artifactId>
|
|
||||||
<version>44ed40f8ce</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.jnr</groupId>
|
|
||||||
<artifactId>jnr-ffi</artifactId>
|
|
||||||
<version>2.2.16</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.jnr</groupId>
|
|
||||||
<artifactId>jnr-posix</artifactId>
|
|
||||||
<version>3.1.19</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.jnr</groupId>
|
|
||||||
<artifactId>jnr-constants</artifactId>
|
|
||||||
<version>0.10.4</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
|||||||
@@ -72,26 +72,6 @@
|
|||||||
<artifactId>quarkus-junit5</artifactId>
|
<artifactId>quarkus-junit5</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.SerCeMan</groupId>
|
|
||||||
<artifactId>jnr-fuse</artifactId>
|
|
||||||
<version>44ed40f8ce</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.jnr</groupId>
|
|
||||||
<artifactId>jnr-ffi</artifactId>
|
|
||||||
<version>2.2.16</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.jnr</groupId>
|
|
||||||
<artifactId>jnr-posix</artifactId>
|
|
||||||
<version>3.1.19</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.jnr</groupId>
|
|
||||||
<artifactId>jnr-constants</artifactId>
|
|
||||||
<version>0.10.4</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.usatiuk.dhfs.files.objects;
|
package com.usatiuk.dhfs.files.objects;
|
||||||
|
|
||||||
import com.usatiuk.dhfs.JDataRemote;
|
import com.usatiuk.dhfs.JDataRemote;
|
||||||
import com.usatiuk.objects.JObjectKey;
|
|
||||||
import com.usatiuk.dhfs.jmap.JMapHolder;
|
import com.usatiuk.dhfs.jmap.JMapHolder;
|
||||||
import com.usatiuk.dhfs.jmap.JMapLongKey;
|
import com.usatiuk.dhfs.jmap.JMapLongKey;
|
||||||
import com.usatiuk.dhfs.repository.JDataRemoteDto;
|
import com.usatiuk.dhfs.repository.JDataRemoteDto;
|
||||||
|
import com.usatiuk.objects.JObjectKey;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -28,6 +28,10 @@ public record File(JObjectKey key, long mode, long cTime, long mTime,
|
|||||||
return new File(key, mode, cTime, mTime, symlink);
|
return new File(key, mode, cTime, mTime, symlink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File withCurrentMTime() {
|
||||||
|
return new File(key, mode, cTime, System.currentTimeMillis(), symlink);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<JObjectKey> collectRefsTo() {
|
public Collection<JObjectKey> collectRefsTo() {
|
||||||
return Set.of();
|
return Set.of();
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
|||||||
} else if (dent instanceof RemoteObjectMeta) {
|
} else if (dent instanceof RemoteObjectMeta) {
|
||||||
var remote = remoteTx.getData(JDataRemote.class, uuid).orElse(null);
|
var remote = remoteTx.getData(JDataRemote.class, uuid).orElse(null);
|
||||||
if (remote instanceof File f) {
|
if (remote instanceof File f) {
|
||||||
remoteTx.putData(f.withMode(mode).withMTime(System.currentTimeMillis()));
|
remoteTx.putData(f.withMode(mode).withCurrentMTime());
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException(uuid + " is not a file");
|
throw new IllegalArgumentException(uuid + " is not a file");
|
||||||
@@ -453,7 +453,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
|||||||
jMapHelper.put(file, JMapLongKey.of(e.getKey()), e.getValue());
|
jMapHelper.put(file, JMapLongKey.of(e.getKey()), e.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteTx.putData(file);
|
remoteTx.putData(file.withCurrentMTime());
|
||||||
|
|
||||||
return (long) data.size();
|
return (long) data.size();
|
||||||
});
|
});
|
||||||
@@ -544,7 +544,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
|||||||
jMapHelper.put(file, JMapLongKey.of(e.getKey()), e.getValue());
|
jMapHelper.put(file, JMapLongKey.of(e.getKey()), e.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteTx.putData(file);
|
remoteTx.putData(file.withCurrentMTime());
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ public abstract class DhfsFileServiceSimpleTestImpl {
|
|||||||
|
|
||||||
var uuid = ret.get();
|
var uuid = ret.get();
|
||||||
|
|
||||||
|
var curMtime = fileService.getattr(uuid).get().mtime();
|
||||||
fileService.write(uuid, 0, new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
|
fileService.write(uuid, 0, new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
|
||||||
Assertions.assertArrayEquals(new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, fileService.read(uuid, 0, 10).get().toByteArray());
|
Assertions.assertArrayEquals(new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, fileService.read(uuid, 0, 10).get().toByteArray());
|
||||||
Assertions.assertArrayEquals(new byte[]{2, 3, 4, 5, 6, 7, 8, 9}, fileService.read(uuid, 2, 8).get().toByteArray());
|
Assertions.assertArrayEquals(new byte[]{2, 3, 4, 5, 6, 7, 8, 9}, fileService.read(uuid, 2, 8).get().toByteArray());
|
||||||
@@ -123,6 +124,9 @@ public abstract class DhfsFileServiceSimpleTestImpl {
|
|||||||
fileService.write(uuid, 3, new byte[]{17, 18});
|
fileService.write(uuid, 3, new byte[]{17, 18});
|
||||||
Assertions.assertArrayEquals(new byte[]{0, 1, 2, 17, 18, 11, 15, 16, 8, 9, 13, 14}, fileService.read(uuid, 0, 12).get().toByteArray());
|
Assertions.assertArrayEquals(new byte[]{0, 1, 2, 17, 18, 11, 15, 16, 8, 9, 13, 14}, fileService.read(uuid, 0, 12).get().toByteArray());
|
||||||
|
|
||||||
|
var newMtime = fileService.getattr(uuid).get().mtime();
|
||||||
|
Assertions.assertTrue(newMtime > curMtime);
|
||||||
|
|
||||||
fileService.unlink("/writeTest");
|
fileService.unlink("/writeTest");
|
||||||
Assertions.assertFalse(fileService.open("/writeTest").isPresent());
|
Assertions.assertFalse(fileService.open("/writeTest").isPresent());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,24 +73,9 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.SerCeMan</groupId>
|
<groupId>com.github.serceman</groupId>
|
||||||
<artifactId>jnr-fuse</artifactId>
|
<artifactId>jnr-fuse</artifactId>
|
||||||
<version>44ed40f8ce</version>
|
<version>0.5.8</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.jnr</groupId>
|
|
||||||
<artifactId>jnr-ffi</artifactId>
|
|
||||||
<version>2.2.16</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.jnr</groupId>
|
|
||||||
<artifactId>jnr-posix</artifactId>
|
|
||||||
<version>3.1.19</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.jnr</groupId>
|
|
||||||
<artifactId>jnr-constants</artifactId>
|
|
||||||
<version>0.10.4</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
|
|||||||
@@ -17,30 +17,27 @@ public interface TransactionManager {
|
|||||||
return supplier.get();
|
return supplier.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
begin();
|
while (true) {
|
||||||
T ret;
|
begin();
|
||||||
try {
|
boolean commit = false;
|
||||||
ret = supplier.get();
|
try {
|
||||||
} catch (TxCommitException txCommitException) {
|
var ret = supplier.get();
|
||||||
rollback();
|
commit = true;
|
||||||
if (tries == 0) {
|
commit();
|
||||||
Log.error("Transaction commit failed", txCommitException);
|
return ret;
|
||||||
throw txCommitException;
|
} catch (TxCommitException txCommitException) {
|
||||||
|
if (!commit)
|
||||||
|
rollback();
|
||||||
|
if (tries == 0) {
|
||||||
|
Log.error("Transaction commit failed", txCommitException);
|
||||||
|
throw txCommitException;
|
||||||
|
}
|
||||||
|
tries--;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
if (!commit)
|
||||||
|
rollback();
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
return runTries(supplier, tries - 1);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
commit();
|
|
||||||
return ret;
|
|
||||||
} catch (TxCommitException txCommitException) {
|
|
||||||
if (tries == 0) {
|
|
||||||
Log.error("Transaction commit failed", txCommitException);
|
|
||||||
throw txCommitException;
|
|
||||||
}
|
|
||||||
return runTries(supplier, tries - 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,29 +52,29 @@ public interface TransactionManager {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
begin();
|
while (true) {
|
||||||
try {
|
begin();
|
||||||
fn.apply();
|
boolean commit = false;
|
||||||
} catch (TxCommitException txCommitException) {
|
try {
|
||||||
rollback();
|
fn.apply();
|
||||||
if (tries == 0) {
|
commit = true;
|
||||||
Log.error("Transaction commit failed", txCommitException);
|
var ret = commit();
|
||||||
throw txCommitException;
|
return ret;
|
||||||
|
} catch (TxCommitException txCommitException) {
|
||||||
|
if (!commit)
|
||||||
|
rollback();
|
||||||
|
if (tries == 0) {
|
||||||
|
Log.error("Transaction commit failed", txCommitException);
|
||||||
|
throw txCommitException;
|
||||||
|
}
|
||||||
|
tries--;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
if (!commit)
|
||||||
|
rollback();
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
return runTries(fn, tries - 1);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return commit();
|
|
||||||
} catch (TxCommitException txCommitException) {
|
|
||||||
if (tries == 0) {
|
|
||||||
Log.error("Transaction commit failed", txCommitException);
|
|
||||||
throw txCommitException;
|
|
||||||
}
|
|
||||||
return runTries(fn, tries - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default TransactionHandle run(VoidFn fn) {
|
default TransactionHandle run(VoidFn fn) {
|
||||||
|
|||||||
@@ -35,13 +35,6 @@
|
|||||||
<dhfs.native-libs-dir>${project.parent.build.outputDirectory}/native</dhfs.native-libs-dir>
|
<dhfs.native-libs-dir>${project.parent.build.outputDirectory}/native</dhfs.native-libs-dir>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>jitpack.io</id>
|
|
||||||
<url>https://jitpack.io</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -72,26 +72,6 @@
|
|||||||
<artifactId>quarkus-junit5</artifactId>
|
<artifactId>quarkus-junit5</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.SerCeMan</groupId>
|
|
||||||
<artifactId>jnr-fuse</artifactId>
|
|
||||||
<version>44ed40f8ce</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.jnr</groupId>
|
|
||||||
<artifactId>jnr-ffi</artifactId>
|
|
||||||
<version>2.2.16</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.jnr</groupId>
|
|
||||||
<artifactId>jnr-posix</artifactId>
|
|
||||||
<version>3.1.19</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.jnr</groupId>
|
|
||||||
<artifactId>jnr-constants</artifactId>
|
|
||||||
<version>0.10.4</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
|||||||
Reference in New Issue
Block a user