-
Notifications
You must be signed in to change notification settings - Fork 702
feat: add additional layers support #7128
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
Draft
Retrospection
wants to merge
6
commits into
apache:main
Choose a base branch
from
Retrospection:java-additional-layers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b85d17
[java] Add additional layers support
Retrospection 0079613
[java] Fix code formatting with spotless
Retrospection ce093e5
chore: remove design doc
Retrospection 554b6e2
[java] Reorder layers alphabetically for taplo compliance
Retrospection 05fddba
feat: remove hotpath layer and logging layer.
Retrospection 1977a36
chore: fix fmt error.
Retrospection File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
bindings/java/src/main/java/org/apache/opendal/layer/LoggingLayer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * 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.opendal.layer; | ||
|
|
||
| import org.apache.opendal.Layer; | ||
|
|
||
| /** | ||
| * This layer adds structured logging for every operation. | ||
| * | ||
| * <p>Note: This layer requires proper logging setup (e.g., log4j2, java.util.logging) to work. | ||
| * Without logging configuration, this layer is a no-op. | ||
| * | ||
| * @see <a href="https://docs.rs/opendal/latest/opendal/layers/struct.LoggingLayer.html">LoggingLayer's rustdoc</a> | ||
| */ | ||
| public class LoggingLayer extends Layer { | ||
|
|
||
| /** | ||
| * Create a new LoggingLayer. | ||
| */ | ||
| public LoggingLayer() {} | ||
|
|
||
| @Override | ||
| protected long layer(long nativeOp) { | ||
| return doLayer(nativeOp); | ||
| } | ||
|
|
||
| private static native long doLayer(long nativeHandle); | ||
| } | ||
42 changes: 42 additions & 0 deletions
42
bindings/java/src/main/java/org/apache/opendal/layer/MimeGuessLayer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * 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.opendal.layer; | ||
|
|
||
| import org.apache.opendal.Layer; | ||
|
|
||
| /** | ||
| * This layer will automatically set Content-Type based on the file extension in the path. | ||
| * | ||
| * @see <a href="https://docs.rs/opendal/latest/opendal/layers/struct.MimeGuessLayer.html">MimeGuessLayer's rustdoc</a> | ||
| */ | ||
| public class MimeGuessLayer extends Layer { | ||
|
|
||
| /** | ||
| * Create a new MimeGuessLayer. | ||
| */ | ||
| public MimeGuessLayer() {} | ||
|
|
||
| @Override | ||
| protected long layer(long nativeOp) { | ||
| return doLayer(nativeOp); | ||
| } | ||
|
|
||
| private static native long doLayer(long nativeHandle); | ||
| } |
58 changes: 58 additions & 0 deletions
58
bindings/java/src/main/java/org/apache/opendal/layer/ThrottleLayer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * 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.opendal.layer; | ||
|
|
||
| import org.apache.opendal.Layer; | ||
|
|
||
| /** | ||
| * This layer adds a bandwidth rate limiter to the underlying services. | ||
| * | ||
| * @see <a href="https://docs.rs/opendal/latest/opendal/layers/struct.ThrottleLayer.html">ThrottleLayer's rustdoc</a> | ||
| */ | ||
| public class ThrottleLayer extends Layer { | ||
|
|
||
| private final long bandwidth; | ||
|
|
||
| private final long burst; | ||
|
|
||
| /** | ||
| * Create a new ThrottleLayer with given bandwidth and burst. | ||
| * | ||
| * @param bandwidth the maximum number of bytes allowed to pass through per second | ||
| * @param burst the maximum number of bytes allowed to pass through at once | ||
| */ | ||
| public ThrottleLayer(long bandwidth, long burst) { | ||
| if (bandwidth <= 0) { | ||
| throw new IllegalArgumentException("bandwidth must be positive"); | ||
| } | ||
| if (burst <= 0) { | ||
| throw new IllegalArgumentException("burst must be positive"); | ||
| } | ||
| this.bandwidth = bandwidth; | ||
| this.burst = burst; | ||
| } | ||
|
|
||
| @Override | ||
| protected long layer(long nativeOp) { | ||
| return doLayer(nativeOp, bandwidth, burst); | ||
| } | ||
|
|
||
| private static native long doLayer(long nativeHandle, long bandwidth, long burst); | ||
| } |
82 changes: 82 additions & 0 deletions
82
bindings/java/src/main/java/org/apache/opendal/layer/TimeoutLayer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * 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.opendal.layer; | ||
|
|
||
| import java.time.Duration; | ||
| import org.apache.opendal.Layer; | ||
|
|
||
| /** | ||
| * This layer adds timeout for every operation to avoid slow or unexpected hang operations. | ||
| * | ||
| * @see <a href="https://docs.rs/opendal/latest/opendal/layers/struct.TimeoutLayer.html">TimeoutLayer's rustdoc</a> | ||
| */ | ||
| public class TimeoutLayer extends Layer { | ||
|
|
||
| private final Duration timeout; | ||
|
|
||
| private final Duration ioTimeout; | ||
|
|
||
| /** | ||
| * Create a new TimeoutLayer with default settings. | ||
| * Default timeout: 60 seconds for non-IO operations, 10 seconds for IO operations. | ||
| */ | ||
| public TimeoutLayer() { | ||
| this.timeout = Duration.ofSeconds(60); | ||
| this.ioTimeout = Duration.ofSeconds(10); | ||
| } | ||
|
|
||
| /** | ||
| * Create a new TimeoutLayer with custom timeout settings. | ||
| * | ||
| * @param timeout timeout for non-IO operations (stat, delete, etc.) | ||
| * @param ioTimeout timeout for IO operations (read, write, etc.) | ||
| */ | ||
| public TimeoutLayer(Duration timeout, Duration ioTimeout) { | ||
| this.timeout = timeout; | ||
| this.ioTimeout = ioTimeout; | ||
| } | ||
|
|
||
| /** | ||
| * Set timeout for non-IO operations. | ||
| * | ||
| * @param timeout the timeout duration | ||
| * @return this TimeoutLayer for chaining | ||
| */ | ||
| public TimeoutLayer withTimeout(Duration timeout) { | ||
| return new TimeoutLayer(timeout, this.ioTimeout); | ||
| } | ||
|
|
||
| /** | ||
| * Set timeout for IO operations. | ||
| * | ||
| * @param ioTimeout the IO timeout duration | ||
| * @return this TimeoutLayer for chaining | ||
| */ | ||
| public TimeoutLayer withIoTimeout(Duration ioTimeout) { | ||
| return new TimeoutLayer(this.timeout, ioTimeout); | ||
| } | ||
|
|
||
| @Override | ||
| protected long layer(long nativeOp) { | ||
| return doLayer(nativeOp, timeout.toNanos(), ioTimeout.toNanos()); | ||
| } | ||
|
|
||
| private static native long doLayer(long nativeHandle, long timeout, long ioTimeout); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, please understand your changes first.
LoggingLayerintegrate rust'slogcrate and thus requires we to provide aset_loggercall. Users can't configure that throughlog4j2orjava.util.logging.Maybe we can start a discussion thread on how we do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for rough pr.
Honestly I'm not that familiar with this binding layer, and just think this can be implemented with ai just because it has other language implementation as reference.
I'll do some research to understand what the binding layer is for and then do discussion about implementation.
Thanks for kindly review.