-
Notifications
You must be signed in to change notification settings - Fork 154
[Issue #707] implement stream storage #773
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6cd4f98
implement stream storage
huasiy dc43987
fix no data bug in stream storage
huasiy 19f30ef
implement physical reader and writer
huasiy 86f4481
fail when data sent larger than 800M occasionally
huasiy fc3c20d
stream storage work normally
huasiy 87c3e4f
resolve comments
huasiy 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
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
pixels-common/src/main/java/io/pixelsdb/pixels/common/physical/StreamPath.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,56 @@ | ||
| /* | ||
| * Copyright 2024 PixelsDB. | ||
| * | ||
| * This file is part of Pixels. | ||
| * | ||
| * Pixels is free software: you can redistribute it and/or modify | ||
| * it under the terms of the Affero GNU General Public License as | ||
| * published by the Free Software Foundation, either version 3 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * Pixels is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Affero GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the Affero GNU General Public | ||
| * License along with Pixels. If not, see | ||
| * <https://www.gnu.org/licenses/>. | ||
| */ | ||
| package io.pixelsdb.pixels.common.physical; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class StreamPath | ||
| { | ||
| private String host; | ||
| private int port; | ||
| public boolean valid = false; | ||
|
|
||
| public StreamPath(String path) | ||
| { | ||
| requireNonNull(path); | ||
| if (path.contains("://")) | ||
| { | ||
| path = path.substring(path.indexOf("://") + 3); | ||
| } | ||
| int colon = path.indexOf(':'); | ||
| if (colon > 0) | ||
| { | ||
| host = path.substring(0, colon); | ||
| port = Integer.parseInt(path.substring(colon + 1)); | ||
| this.valid = true; | ||
| } | ||
| } | ||
|
|
||
| public String getHostName() | ||
| { | ||
| return host; | ||
| } | ||
|
|
||
| public int getPort() | ||
| { | ||
| return port; | ||
| } | ||
|
|
||
| } | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>io.pixelsdb</groupId> | ||
| <artifactId>pixels</artifactId> | ||
| <version>0.2.0-SNAPSHOT</version> | ||
| <relativePath>../../pom.xml</relativePath> | ||
| </parent> | ||
|
|
||
| <artifactId>pixels-storage-stream</artifactId> | ||
|
|
||
| <properties> | ||
| <maven.compiler.source>8</maven.compiler.source> | ||
| <maven.compiler.target>8</maven.compiler.target> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.pixelsdb</groupId> | ||
| <artifactId>pixels-common</artifactId> | ||
| <optional>true</optional> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>net.java.dev.jna</groupId> | ||
| <artifactId>jna</artifactId> | ||
| </dependency> | ||
|
|
||
| <!-- asynchttpclient --> | ||
| <dependency> | ||
| <groupId>org.asynchttpclient</groupId> | ||
| <artifactId>async-http-client</artifactId> | ||
| <optional>true</optional> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.netty</groupId> | ||
| <artifactId>netty-all</artifactId> | ||
| <optional>true</optional> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.apache.hadoop</groupId> | ||
| <artifactId>hadoop-client</artifactId> | ||
| <optional>true</optional> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.guava</groupId> | ||
| <artifactId>guava</artifactId> | ||
| <optional>true</optional> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-deploy-plugin</artifactId> | ||
| <version>${maven.plugin.deploy.version}</version> | ||
| <configuration> | ||
| <altDeploymentRepository> | ||
| local.mvn.repo::default::file://${project.parent.basedir}/mvn | ||
| </altDeploymentRepository> | ||
| </configuration> | ||
| </plugin> | ||
|
|
||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-source-plugin</artifactId> | ||
| <version>${maven.plugin.source.version}</version> | ||
| <executions> | ||
| <execution> | ||
| <id>attach-sources</id> | ||
| <goals> | ||
| <goal>jar</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
157 changes: 157 additions & 0 deletions
157
...-storage-stream/src/main/java/io/pixelsdb/pixels/storage/stream/PhysicalStreamReader.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,157 @@ | ||
| /* | ||
| * Copyright 2024 PixelsDB. | ||
| * | ||
| * This file is part of Pixels. | ||
| * | ||
| * Pixels is free software: you can redistribute it and/or modify | ||
| * it under the terms of the Affero GNU General Public License as | ||
| * published by the Free Software Foundation, either version 3 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * Pixels is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Affero GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the Affero GNU General Public | ||
| * License along with Pixels. If not, see | ||
| * <https://www.gnu.org/licenses/>. | ||
| */ | ||
| package io.pixelsdb.pixels.storage.stream; | ||
huasiy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import io.pixelsdb.pixels.common.physical.PhysicalReader; | ||
| import io.pixelsdb.pixels.common.physical.Storage; | ||
|
|
||
| import java.io.DataInputStream; | ||
| import java.io.IOException; | ||
| import java.nio.ByteBuffer; | ||
| import java.nio.ByteOrder; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.ExecutorService; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class PhysicalStreamReader implements PhysicalReader | ||
| { | ||
| private final Storage stream; | ||
| private final String path; | ||
| private final DataInputStream dataInputStream; | ||
|
|
||
| public PhysicalStreamReader(Storage storage, String path) throws IOException | ||
| { | ||
| if (storage instanceof Stream) | ||
| { | ||
| this.stream = (Stream) storage; | ||
| } | ||
| else | ||
| { | ||
| throw new IOException("Storage is not LocalFS."); | ||
| } | ||
| this.path = path; | ||
| this.dataInputStream = storage.open(path); | ||
| } | ||
|
|
||
| @Override | ||
| public long getFileLength() throws IOException | ||
| { | ||
| throw new UnsupportedOperationException("Can't get file length in PhysicalStreamReader"); | ||
| } | ||
|
|
||
| @Override | ||
| public void seek(long desired) throws IOException | ||
| { | ||
| throw new UnsupportedOperationException("Can't seek in PhysicalStreamReader"); | ||
| } | ||
|
|
||
| @Override | ||
| public ByteBuffer readFully(int length) throws IOException | ||
| { | ||
| byte[] buffer = new byte[length]; | ||
| dataInputStream.readFully(buffer); | ||
| return ByteBuffer.wrap(buffer); | ||
| } | ||
|
|
||
| @Override | ||
| public void readFully(byte[] buffer) throws IOException | ||
| { | ||
| dataInputStream.readFully(buffer); | ||
| } | ||
|
|
||
| @Override | ||
| public void readFully(byte[] buffer, int offset, int length) throws IOException | ||
| { | ||
| dataInputStream.readFully(buffer, offset, length); | ||
| } | ||
|
|
||
| @Override | ||
| public long readLong(ByteOrder byteOrder) throws IOException | ||
| { | ||
| if (requireNonNull(byteOrder).equals(ByteOrder.BIG_ENDIAN)) | ||
| { | ||
| return dataInputStream.readLong(); | ||
| } | ||
| else | ||
| { | ||
| return Long.reverseBytes(dataInputStream.readLong()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public int readInt(ByteOrder byteOrder) throws IOException | ||
| { | ||
| if (requireNonNull(byteOrder).equals(ByteOrder.BIG_ENDIAN)) | ||
| { | ||
| return dataInputStream.readInt(); | ||
| } | ||
| else | ||
| { | ||
| return Integer.reverseBytes(dataInputStream.readInt()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean supportsAsync() { return false; } | ||
|
|
||
| @Override | ||
| public CompletableFuture<ByteBuffer> readAsync(long offset, int len) throws IOException | ||
| { | ||
| throw new UnsupportedOperationException("Can't read async in PhysicalStreamReader"); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws IOException | ||
| { | ||
| this.dataInputStream.close(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPath() { return path; } | ||
|
|
||
| /** | ||
| * Get the port in path. | ||
| * | ||
| * @return | ||
| */ | ||
| @Override | ||
| public String getName() | ||
| { | ||
| if (path == null) | ||
| { | ||
| return null; | ||
| } | ||
| int slash = path.lastIndexOf(":"); | ||
| return path.substring(slash + 1); | ||
| } | ||
|
|
||
| @Override | ||
| public long getBlockId() throws IOException | ||
| { | ||
| throw new IOException("Can't get block id in PhysicalStreamReader"); | ||
| } | ||
|
|
||
| @Override | ||
| public Storage.Scheme getStorageScheme() { return stream.getScheme(); } | ||
|
|
||
| @Override | ||
| public int getNumReadRequests() { return 0; } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.