You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by "chibenwa (via GitHub)" <gi...@apache.org> on 2023/10/29 21:09:49 UTC
[PR] JAMES-3953 Provide a file based blob store [james-project]
chibenwa opened a new pull request, #1766:
URL: https://github.com/apache/james-project/pull/1766
See the ticket for details but in short having such a card in the James game would ease integrating James into legacy storage systems, not cloud / s3 ready. Think ISCI, SAN, NAS and distributed systems like CEPH...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-3953 Provide a file based blob store [james-project]
Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on code in PR #1766:
URL: https://github.com/apache/james-project/pull/1766#discussion_r1375740275
##########
server/blob/blob-file/src/main/java/org/apache/james/blob/file/FileBlobStoreDAO.java:
##########
@@ -0,0 +1,188 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.blob.file;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.nio.channels.OverlappingFileLockException;
+import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
+import java.time.Duration;
+import java.util.Collection;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.james.blob.api.BlobId;
+import org.apache.james.blob.api.BlobStoreDAO;
+import org.apache.james.blob.api.BucketName;
+import org.apache.james.blob.api.ObjectNotFoundException;
+import org.apache.james.blob.api.ObjectStoreIOException;
+import org.apache.james.filesystem.api.FileSystem;
+import org.reactivestreams.Publisher;
+
+import com.github.fge.lambdas.Throwing;
+import com.google.common.base.Preconditions;
+import com.google.common.io.ByteSource;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+import reactor.util.retry.Retry;
+
+public class FileBlobStoreDAO implements BlobStoreDAO {
+
+ private final File root;
+ private final BlobId.Factory blobIdFactory;
+
+ public FileBlobStoreDAO(FileSystem fileSystem, BlobId.Factory blobIdFactory) throws FileNotFoundException {
+ root = fileSystem.getFile("file://var/blob");
+ this.blobIdFactory = blobIdFactory;
+ }
+
+ @Override
+ public InputStream read(BucketName bucketName, BlobId blobId) throws ObjectStoreIOException, ObjectNotFoundException {
+ File bucketRoot = getBucketRoot(bucketName);
+ File blob = new File(bucketRoot, blobId.asString());
+ try {
+ return new FileInputStream(blob);
+ } catch (FileNotFoundException e) {
+ throw new ObjectNotFoundException(String.format("Cannot locate %s within %s", blobId.asString(), bucketName.asString()), e);
+ }
+ }
+
+ private File getBucketRoot(BucketName bucketName) {
+ File bucketRoot = new File(root, bucketName.asString());
+ if (!bucketRoot.exists()) {
+ try {
+ FileUtils.forceMkdir(bucketRoot);
+ } catch (IOException e) {
+ throw new ObjectStoreIOException("Cannot create bucket", e);
+ }
+ }
+ return bucketRoot;
+ }
+
+ @Override
+ public Mono<InputStream> readReactive(BucketName bucketName, BlobId blobId) {
+ return Mono.fromCallable(() -> read(bucketName, blobId))
+ .subscribeOn(Schedulers.boundedElastic());
+ }
+
+ @Override
+ public Mono<byte[]> readBytes(BucketName bucketName, BlobId blobId) {
+ return readReactive(bucketName, blobId)
+ .map(Throwing.<InputStream, byte[]>function(IOUtils::toByteArray).sneakyThrow());
+ }
+
+ @Override
+ public Mono<Void> save(BucketName bucketName, BlobId blobId, byte[] data) {
+ return save(bucketName, blobId, new ByteArrayInputStream(data));
+ }
+
+ @Override
+ public Mono<Void> save(BucketName bucketName, BlobId blobId, InputStream inputStream) {
+ Preconditions.checkNotNull(inputStream);
+ File bucketRoot = getBucketRoot(bucketName);
+ File blob = new File(bucketRoot, blobId.asString());
+ return Mono.fromRunnable(() -> {
+ save(inputStream, blob);
+ })
Review Comment:
```
return Mono.fromRunnable(() -> save(inputStream, blob))
```
##########
server/blob/blob-file/src/main/java/org/apache/james/blob/file/FileBlobStoreDAO.java:
##########
@@ -0,0 +1,188 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.blob.file;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.nio.channels.OverlappingFileLockException;
+import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
+import java.time.Duration;
+import java.util.Collection;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.james.blob.api.BlobId;
+import org.apache.james.blob.api.BlobStoreDAO;
+import org.apache.james.blob.api.BucketName;
+import org.apache.james.blob.api.ObjectNotFoundException;
+import org.apache.james.blob.api.ObjectStoreIOException;
+import org.apache.james.filesystem.api.FileSystem;
+import org.reactivestreams.Publisher;
+
+import com.github.fge.lambdas.Throwing;
+import com.google.common.base.Preconditions;
+import com.google.common.io.ByteSource;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+import reactor.util.retry.Retry;
+
+public class FileBlobStoreDAO implements BlobStoreDAO {
+
+ private final File root;
+ private final BlobId.Factory blobIdFactory;
+
+ public FileBlobStoreDAO(FileSystem fileSystem, BlobId.Factory blobIdFactory) throws FileNotFoundException {
+ root = fileSystem.getFile("file://var/blob");
+ this.blobIdFactory = blobIdFactory;
+ }
+
+ @Override
+ public InputStream read(BucketName bucketName, BlobId blobId) throws ObjectStoreIOException, ObjectNotFoundException {
+ File bucketRoot = getBucketRoot(bucketName);
+ File blob = new File(bucketRoot, blobId.asString());
+ try {
+ return new FileInputStream(blob);
+ } catch (FileNotFoundException e) {
+ throw new ObjectNotFoundException(String.format("Cannot locate %s within %s", blobId.asString(), bucketName.asString()), e);
+ }
+ }
+
+ private File getBucketRoot(BucketName bucketName) {
+ File bucketRoot = new File(root, bucketName.asString());
+ if (!bucketRoot.exists()) {
+ try {
+ FileUtils.forceMkdir(bucketRoot);
+ } catch (IOException e) {
+ throw new ObjectStoreIOException("Cannot create bucket", e);
+ }
+ }
+ return bucketRoot;
+ }
+
+ @Override
+ public Mono<InputStream> readReactive(BucketName bucketName, BlobId blobId) {
+ return Mono.fromCallable(() -> read(bucketName, blobId))
+ .subscribeOn(Schedulers.boundedElastic());
+ }
+
+ @Override
+ public Mono<byte[]> readBytes(BucketName bucketName, BlobId blobId) {
+ return readReactive(bucketName, blobId)
+ .map(Throwing.<InputStream, byte[]>function(IOUtils::toByteArray).sneakyThrow());
+ }
+
+ @Override
+ public Mono<Void> save(BucketName bucketName, BlobId blobId, byte[] data) {
+ return save(bucketName, blobId, new ByteArrayInputStream(data));
+ }
+
+ @Override
+ public Mono<Void> save(BucketName bucketName, BlobId blobId, InputStream inputStream) {
+ Preconditions.checkNotNull(inputStream);
+ File bucketRoot = getBucketRoot(bucketName);
+ File blob = new File(bucketRoot, blobId.asString());
+ return Mono.fromRunnable(() -> {
+ save(inputStream, blob);
+ })
+ .subscribeOn(Schedulers.boundedElastic())
+ .then()
+ .retryWhen(Retry.backoff(10, Duration.ofMillis(100))
+ .filter(e -> e instanceof OverlappingFileLockException));
+ }
+
+ private void save(InputStream inputStream, File blob) {
+ if (blob.exists()) {
+ return;
+ }
Review Comment:
line space for readability
##########
server/blob/blob-file/src/main/java/org/apache/james/blob/file/FileBlobStoreFactory.java:
##########
@@ -0,0 +1,44 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.blob.file;
+
+import java.io.FileNotFoundException;
+
+import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.server.blob.deduplication.BlobStoreFactory;
+
+public class FileBlobStoreFactory {
+ private final FileSystem fileSystem;
+
+ public FileBlobStoreFactory(FileSystem fileSystem) {
+ this.fileSystem = fileSystem;
+ }
+
+ public BlobStoreFactory.RequireBlobIdFactory builder() {
+ return blobIfFactory -> {
+ try {
+ return BlobStoreFactory.builder().blobStoreDAO(new FileBlobStoreDAO(fileSystem, blobIfFactory))
Review Comment:
```
return BlobStoreFactory.builder()
.blobStoreDAO(new FileBlobStoreDAO(fileSystem, blobIfFactory))
```
##########
server/container/guice/distributed/src/main/java/org/apache/james/modules/blobstore/BlobStoreModulesChooser.java:
##########
@@ -75,6 +76,15 @@ protected void configure() {
}
}
+ static class FileBlobStoreDAODeclarationModule extends AbstractModule {
+ @Override
+ protected void configure() {
+ install(new CassandraBucketModule());
Review Comment:
Why a Cassandra module?
##########
server/blob/blob-file/src/main/java/org/apache/james/blob/file/FileBlobStoreDAO.java:
##########
@@ -0,0 +1,188 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.blob.file;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.nio.channels.OverlappingFileLockException;
+import java.nio.file.Files;
+import java.nio.file.NoSuchFileException;
+import java.time.Duration;
+import java.util.Collection;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.james.blob.api.BlobId;
+import org.apache.james.blob.api.BlobStoreDAO;
+import org.apache.james.blob.api.BucketName;
+import org.apache.james.blob.api.ObjectNotFoundException;
+import org.apache.james.blob.api.ObjectStoreIOException;
+import org.apache.james.filesystem.api.FileSystem;
+import org.reactivestreams.Publisher;
+
+import com.github.fge.lambdas.Throwing;
+import com.google.common.base.Preconditions;
+import com.google.common.io.ByteSource;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+import reactor.util.retry.Retry;
+
+public class FileBlobStoreDAO implements BlobStoreDAO {
+
+ private final File root;
+ private final BlobId.Factory blobIdFactory;
+
+ public FileBlobStoreDAO(FileSystem fileSystem, BlobId.Factory blobIdFactory) throws FileNotFoundException {
+ root = fileSystem.getFile("file://var/blob");
+ this.blobIdFactory = blobIdFactory;
+ }
+
+ @Override
+ public InputStream read(BucketName bucketName, BlobId blobId) throws ObjectStoreIOException, ObjectNotFoundException {
+ File bucketRoot = getBucketRoot(bucketName);
+ File blob = new File(bucketRoot, blobId.asString());
+ try {
+ return new FileInputStream(blob);
+ } catch (FileNotFoundException e) {
+ throw new ObjectNotFoundException(String.format("Cannot locate %s within %s", blobId.asString(), bucketName.asString()), e);
+ }
+ }
+
+ private File getBucketRoot(BucketName bucketName) {
+ File bucketRoot = new File(root, bucketName.asString());
+ if (!bucketRoot.exists()) {
+ try {
+ FileUtils.forceMkdir(bucketRoot);
+ } catch (IOException e) {
+ throw new ObjectStoreIOException("Cannot create bucket", e);
+ }
+ }
+ return bucketRoot;
+ }
+
+ @Override
+ public Mono<InputStream> readReactive(BucketName bucketName, BlobId blobId) {
+ return Mono.fromCallable(() -> read(bucketName, blobId))
+ .subscribeOn(Schedulers.boundedElastic());
+ }
+
+ @Override
+ public Mono<byte[]> readBytes(BucketName bucketName, BlobId blobId) {
+ return readReactive(bucketName, blobId)
+ .map(Throwing.<InputStream, byte[]>function(IOUtils::toByteArray).sneakyThrow());
+ }
+
+ @Override
+ public Mono<Void> save(BucketName bucketName, BlobId blobId, byte[] data) {
+ return save(bucketName, blobId, new ByteArrayInputStream(data));
+ }
+
+ @Override
+ public Mono<Void> save(BucketName bucketName, BlobId blobId, InputStream inputStream) {
+ Preconditions.checkNotNull(inputStream);
+ File bucketRoot = getBucketRoot(bucketName);
+ File blob = new File(bucketRoot, blobId.asString());
+ return Mono.fromRunnable(() -> {
+ save(inputStream, blob);
+ })
+ .subscribeOn(Schedulers.boundedElastic())
+ .then()
+ .retryWhen(Retry.backoff(10, Duration.ofMillis(100))
+ .filter(e -> e instanceof OverlappingFileLockException));
+ }
+
+ private void save(InputStream inputStream, File blob) {
+ if (blob.exists()) {
+ return;
+ }
+ try (FileOutputStream out = new FileOutputStream(blob);
+ FileChannel channel = out.getChannel();
+ FileLock fileLock = channel.lock()) {
+ inputStream.transferTo(out);
+
Review Comment:
unnecessary empty line
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-3953 Provide a file based blob store [james-project]
Posted by "quantranhong1999 (via GitHub)" <gi...@apache.org>.
quantranhong1999 commented on code in PR #1766:
URL: https://github.com/apache/james-project/pull/1766#discussion_r1375766947
##########
server/blob/blob-file/src/main/java/org/apache/james/blob/file/FileBlobStoreFactory.java:
##########
@@ -0,0 +1,44 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.blob.file;
+
+import java.io.FileNotFoundException;
+
+import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.server.blob.deduplication.BlobStoreFactory;
+
+public class FileBlobStoreFactory {
+ private final FileSystem fileSystem;
+
+ public FileBlobStoreFactory(FileSystem fileSystem) {
+ this.fileSystem = fileSystem;
+ }
+
+ public BlobStoreFactory.RequireBlobIdFactory builder() {
+ return blobIfFactory -> {
+ try {
+ return BlobStoreFactory.builder().blobStoreDAO(new FileBlobStoreDAO(fileSystem, blobIfFactory))
Review Comment:
`blobIfFactory` -> `blobIdFactory`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-3953 Provide a file based blob store [james-project]
Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on PR #1766:
URL: https://github.com/apache/james-project/pull/1766#issuecomment-1788356715
```
21:15:52,002 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.3.0:check (check-style) on project scaling-pulsar-smtp: You have 1 Checkstyle violation. -> [Help 1]
```
And next time fixups would be appreciated so we don't need to review the all PR again :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-3953 Provide a file based blob store [james-project]
Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael commented on PR #1766:
URL: https://github.com/apache/james-project/pull/1766#issuecomment-1784709313
https://ci-builds.apache.org/job/james/job/ApacheJames/job/PR-1766/2/
Failed tests related
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-3953 Provide a file based blob store [james-project]
Posted by "Arsnael (via GitHub)" <gi...@apache.org>.
Arsnael merged PR #1766:
URL: https://github.com/apache/james-project/pull/1766
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org