mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-28 20:47:49 +01:00
add some checks
why does it break?
This commit is contained in:
@@ -339,6 +339,11 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
||||
|
||||
@Override
|
||||
public Optional<ByteString> read(String fileUuid, long offset, int length) {
|
||||
if (length < 0)
|
||||
throw new StatusRuntimeException(Status.INVALID_ARGUMENT.withDescription("Length should be more than zero: " + length));
|
||||
if (offset < 0)
|
||||
throw new StatusRuntimeException(Status.INVALID_ARGUMENT.withDescription("Offset should be more than zero: " + offset));
|
||||
|
||||
var fileOpt = jObjectManager.get(fileUuid);
|
||||
if (fileOpt.isEmpty()) {
|
||||
Log.error("File not found when trying to read: " + fileUuid);
|
||||
@@ -453,6 +458,9 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
||||
|
||||
@Override
|
||||
public Long write(String fileUuid, long offset, byte[] data) {
|
||||
if (offset < 0)
|
||||
throw new StatusRuntimeException(Status.INVALID_ARGUMENT.withDescription("Offset should be more than zero: " + offset));
|
||||
|
||||
var fileOpt = jObjectManager.get(fileUuid);
|
||||
if (fileOpt.isEmpty()) {
|
||||
Log.error("File not found when trying to read: " + fileUuid);
|
||||
@@ -590,6 +598,9 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
||||
|
||||
@Override
|
||||
public Boolean truncate(String fileUuid, long length) {
|
||||
if (length < 0)
|
||||
throw new StatusRuntimeException(Status.INVALID_ARGUMENT.withDescription("Length should be more than zero: " + length));
|
||||
|
||||
var fileOpt = jObjectManager.get(fileUuid);
|
||||
if (fileOpt.isEmpty()) {
|
||||
Log.error("File not found when trying to read: " + fileUuid);
|
||||
@@ -628,17 +639,17 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
||||
var removedChunks = new LinkedHashSet<String>();
|
||||
|
||||
if (curSize < length) {
|
||||
int combinedSize = (int) (length - curSize);
|
||||
long combinedSize = (length - curSize);
|
||||
|
||||
long start = curSize;
|
||||
|
||||
// Hack
|
||||
HashMap<Integer, ByteString> zeroCache = new HashMap<>();
|
||||
HashMap<Long, ByteString> zeroCache = new HashMap<>();
|
||||
|
||||
{
|
||||
int cur = 0;
|
||||
long cur = 0;
|
||||
while (cur < combinedSize) {
|
||||
int end;
|
||||
long end;
|
||||
|
||||
if (targetChunkSize <= 0)
|
||||
end = combinedSize;
|
||||
@@ -651,7 +662,7 @@ public class DhfsFileServiceImpl implements DhfsFileService {
|
||||
}
|
||||
|
||||
if (!zeroCache.containsKey(end - cur))
|
||||
zeroCache.put(end - cur, UnsafeByteOperations.unsafeWrap(new byte[end - cur]));
|
||||
zeroCache.put(end - cur, UnsafeByteOperations.unsafeWrap(new byte[Math.toIntExact(end - cur)]));
|
||||
|
||||
ChunkData newChunkData = createChunk(zeroCache.get(end - cur));
|
||||
ChunkInfo newChunkInfo = new ChunkInfo(newChunkData.getHash(), newChunkData.getBytes().size());
|
||||
|
||||
@@ -147,6 +147,8 @@ public class DhfsFuse extends FuseStubFS {
|
||||
|
||||
@Override
|
||||
public int read(String path, Pointer buf, long size, long offset, FuseFileInfo fi) {
|
||||
if (size < 0) return -ErrorCodes.EINVAL();
|
||||
if (offset < 0) return -ErrorCodes.EINVAL();
|
||||
try {
|
||||
var fileOpt = fileService.open(path);
|
||||
if (fileOpt.isEmpty()) return -ErrorCodes.ENOENT();
|
||||
@@ -163,6 +165,7 @@ public class DhfsFuse extends FuseStubFS {
|
||||
|
||||
@Override
|
||||
public int write(String path, Pointer buf, long size, long offset, FuseFileInfo fi) {
|
||||
if (offset < 0) return -ErrorCodes.EINVAL();
|
||||
try {
|
||||
var fileOpt = fileService.open(path);
|
||||
if (fileOpt.isEmpty()) return -ErrorCodes.ENOENT();
|
||||
@@ -239,6 +242,7 @@ public class DhfsFuse extends FuseStubFS {
|
||||
|
||||
@Override
|
||||
public int truncate(String path, long size) {
|
||||
if (size < 0) return -ErrorCodes.EINVAL();
|
||||
try {
|
||||
var fileOpt = fileService.open(path);
|
||||
if (fileOpt.isEmpty()) return -ErrorCodes.ENOENT();
|
||||
|
||||
@@ -173,7 +173,7 @@ public class JObjectWriteback {
|
||||
if (_objects.size() < limit) {
|
||||
if (overload) {
|
||||
overload = false;
|
||||
Log.info("Writeback cache enabled");
|
||||
Log.trace("Writeback cache enabled");
|
||||
}
|
||||
_objects.put(name, Pair.of(System.currentTimeMillis(), object));
|
||||
_objects.notifyAll();
|
||||
@@ -184,7 +184,7 @@ public class JObjectWriteback {
|
||||
try {
|
||||
if (!overload) {
|
||||
overload = true;
|
||||
Log.info("Writeback cache disabled");
|
||||
Log.trace("Writeback cache disabled");
|
||||
}
|
||||
flushOneImmediate(object.getMeta(), object.getData());
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user