-
Notifications
You must be signed in to change notification settings - Fork 593
HDDS-5961. [Ozone-Streaming] update the usage space of Containers in … #2833
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,6 +105,7 @@ | |
| import static org.apache.hadoop.hdds.scm.protocolPB.ContainerCommandResponseBuilders.unsupportedRequest; | ||
| import static org.apache.hadoop.hdds.scm.utils.ClientCommandsUtils.getReadChunkVersion; | ||
|
|
||
| import org.apache.ratis.statemachine.StateMachine; | ||
| import org.apache.ratis.thirdparty.com.google.protobuf.ByteString; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
@@ -175,6 +176,17 @@ public VolumeChoosingPolicy getVolumeChoosingPolicyForTesting() { | |
| return volumeChoosingPolicy; | ||
| } | ||
|
|
||
| @Override | ||
| public StateMachine.DataChannel getStreamDataChannel( | ||
|
||
| Container container, ContainerCommandRequestProto msg) | ||
| throws StorageContainerException { | ||
| KeyValueContainer kvContainer = (KeyValueContainer) container; | ||
| checkContainerOpen(kvContainer); | ||
| BlockID blockID = BlockID.getFromProtobuf(msg.getWriteChunk().getBlockID()); | ||
| return chunkManager.getStreamDataChannel(kvContainer, | ||
| blockID, metrics); | ||
| } | ||
|
|
||
| @Override | ||
| public void stop() { | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| * 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.hadoop.ozone.container.keyvalue.impl; | ||
|
|
||
| import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; | ||
| import org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException; | ||
| import org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics; | ||
| import org.apache.hadoop.ozone.container.common.impl.ContainerData; | ||
| import org.apache.ratis.statemachine.StateMachine; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileNotFoundException; | ||
| import java.io.IOException; | ||
| import java.io.RandomAccessFile; | ||
| import java.nio.ByteBuffer; | ||
|
|
||
| /** | ||
| * This class is used to get the DataChannel for streaming. | ||
| */ | ||
| class KeyValueStreamDataChannel implements StateMachine.DataChannel { | ||
| private final RandomAccessFile randomAccessFile; | ||
| private final File file; | ||
|
|
||
| private final ContainerData containerData; | ||
| private final ContainerMetrics metrics; | ||
|
|
||
| KeyValueStreamDataChannel(File file, ContainerData containerData, | ||
| ContainerMetrics metrics) | ||
| throws StorageContainerException { | ||
| try { | ||
| this.file = file; | ||
| this.randomAccessFile = new RandomAccessFile(file, "rw"); | ||
| } catch (FileNotFoundException e) { | ||
| throw new StorageContainerException("BlockFile not exists with " + | ||
| "container Id " + containerData.getContainerID() + | ||
| " file " + file.getAbsolutePath(), | ||
| ContainerProtos.Result.IO_EXCEPTION); | ||
| } | ||
| this.containerData = containerData; | ||
| this.metrics = metrics; | ||
| } | ||
|
|
||
| @Override | ||
| public void force(boolean metadata) throws IOException { | ||
| randomAccessFile.getChannel().force(metadata); | ||
| } | ||
|
|
||
| @Override | ||
| public int write(ByteBuffer src) throws IOException { | ||
| int writeBytes = randomAccessFile.getChannel().write(src); | ||
| metrics | ||
| .incContainerBytesStats(ContainerProtos.Type.StreamWrite, writeBytes); | ||
| containerData.updateWriteStats(writeBytes, false); | ||
|
||
| return writeBytes; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isOpen() { | ||
| return randomAccessFile.getChannel().isOpen(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws IOException { | ||
| randomAccessFile.close(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "KeyValueStreamDataChannel{" + | ||
| "File=" + file.getAbsolutePath() + | ||
| ", containerID=" + containerData.getContainerID() + | ||
| '}'; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,7 @@ enum Type { | |
| GetCommittedBlockLength = 18; | ||
|
|
||
| StreamInit = 19; | ||
| StreamWrite = 20; | ||
| } | ||
|
|
||
|
|
||
|
|
||
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.
Add
@Override.