Skip to content
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

Inconsistency in data if file not found between GoogleStorageWrapper and S3StorageWrapper #91

Closed
hemil-ruparel-blox opened this issue Feb 27, 2024 · 6 comments

Comments

@hemil-ruparel-blox
Copy link
Contributor

In GoogleStorageWrapper, the bytes function returns null if input is null. Otherwise the raw byte array contents of the given file.

Reference - https://github.com/nmondal/cowj/blob/670c91e64a8a936341eaf03d2cd72fd1222bf25b/app/src/main/java/cowj/plugins/GoogleStorageWrapper.java#L102C5-L109C6

@Override
default byte[] bytes(Blob input) {
    try {
        return input.getContent();
    }catch (Throwable t){
        return null;
    }
}

Meanwhile the S3StorageWrapper bytes function returns empty byte array if input is null. This means we cannot distinguish between the case when the file does not exist and when the file is not empty.

Reference - https://github.com/nmondal/cowj/blob/670c91e64a8a936341eaf03d2cd72fd1222bf25b/app/src/main/java/cowj/plugins/S3StorageWrapper.java#L85C5-L89C6

@Override
default byte[] bytes(Entry<String, ResponseBytes<GetObjectResponse>> input){
    return (input == null || input.getValue() == null) ?
            ArrayUtil.EMPTY_BYTE_ARRAY : input.getValue().asByteArray();
}
@hemil-ruparel-blox hemil-ruparel-blox changed the title S3StorageWrapper::bytes should return null if input is null for distinguishing the case of file not being existant and file being empty S3StorageWrapper::bytes should return null if input is null for distinguishing the case of file not being existent and file being empty Feb 27, 2024
@nmondal
Copy link
Owner

nmondal commented Feb 27, 2024

@hemil-ruparel-blox
Copy link
Contributor Author

That would be an extra query no? I want to get the contents of file if exists otherwise null?

@nmondal
Copy link
Owner

nmondal commented Feb 27, 2024

No, it is a head call. Under the hood it always does multiple calls.
Exactly what is being broken by this?

@hemil-ruparel-blox
Copy link
Contributor Author

Nothing major actually. The storage proxy when a file was not found, we used to get 404 because dumpb returned null. Now, it is returning 200 with empty body. The fix is to check if the body is empty before returning which I have done but just wanted to point this out

@hemil-ruparel-blox hemil-ruparel-blox changed the title S3StorageWrapper::bytes should return null if input is null for distinguishing the case of file not being existent and file being empty Inconsistency in data if file not found between GoogleStorageWrapper and S3StorageWrapper Feb 27, 2024
nmondal added a commit that referenced this issue Feb 28, 2024
@nmondal
Copy link
Owner

nmondal commented Feb 28, 2024

@hemil-ruparel-blox take a look around, this is fixed now with protocol change in the Storage ensuring people must conform to this.

@hemil-ruparel-blox
Copy link
Contributor Author

Working as of 7b783ca. A file that does not exist, returns null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants