-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HDDS-1094. Performance test infrastructure : skip writing user data on Datanode. Contributed by Supratim Deka #1323
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
5 commits
Select commit
Hold shift + click to select a range
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
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
162 changes: 162 additions & 0 deletions
162
.../src/main/java/org/apache/hadoop/ozone/container/keyvalue/impl/ChunkManagerDummyImpl.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,162 @@ | ||
| /* | ||
| * 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 com.google.common.base.Preconditions; | ||
| import org.apache.hadoop.hdds.client.BlockID; | ||
| import org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException; | ||
| import org.apache.hadoop.ozone.container.common.helpers.ChunkInfo; | ||
| import org.apache.hadoop.ozone.container.common.interfaces.Container; | ||
| import org.apache.hadoop.ozone.container.common.transport.server.ratis.DispatcherContext; | ||
| import org.apache.hadoop.ozone.container.common.volume.HddsVolume; | ||
| import org.apache.hadoop.ozone.container.common.volume.VolumeIOStats; | ||
| import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData; | ||
| import org.apache.hadoop.util.Time; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.ByteBuffer; | ||
|
|
||
| import static org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.Result.*; | ||
|
|
||
| /** | ||
| * Implementation of ChunkManager built for running performance tests. | ||
| * Chunks are not written to disk, Reads are returned with zero-filled buffers | ||
| */ | ||
| public class ChunkManagerDummyImpl extends ChunkManagerImpl { | ||
| static final Logger LOG = LoggerFactory.getLogger( | ||
| ChunkManagerDummyImpl.class); | ||
|
|
||
| public ChunkManagerDummyImpl(boolean sync) { | ||
| super(sync); | ||
| } | ||
|
|
||
| /** | ||
| * writes a given chunk. | ||
| * | ||
| * @param container - Container for the chunk | ||
| * @param blockID - ID of the block | ||
| * @param info - ChunkInfo | ||
| * @param data - data of the chunk | ||
| * @param dispatcherContext - dispatcherContextInfo | ||
| * @throws StorageContainerException | ||
| */ | ||
| @Override | ||
| public void writeChunk(Container container, BlockID blockID, ChunkInfo info, | ||
| ByteBuffer data, DispatcherContext dispatcherContext) | ||
| throws StorageContainerException { | ||
| long writeTimeStart = Time.monotonicNow(); | ||
|
|
||
| Preconditions.checkNotNull(dispatcherContext); | ||
| DispatcherContext.WriteChunkStage stage = dispatcherContext.getStage(); | ||
|
|
||
| Logger log = LoggerFactory.getLogger(ChunkManagerImpl.class); | ||
|
|
||
| try { | ||
| KeyValueContainerData containerData = | ||
| (KeyValueContainerData) container.getContainerData(); | ||
| HddsVolume volume = containerData.getVolume(); | ||
| VolumeIOStats volumeIOStats = volume.getVolumeIOStats(); | ||
| int bufferSize; | ||
|
|
||
| switch (stage) { | ||
| case WRITE_DATA: | ||
| bufferSize = data.capacity(); | ||
| if (bufferSize != info.getLen()) { | ||
| String err = String.format("data array does not match the length " | ||
| + "specified. DataLen: %d Byte Array: %d", | ||
| info.getLen(), bufferSize); | ||
| log.error(err); | ||
| throw new StorageContainerException(err, INVALID_WRITE_SIZE); | ||
| } | ||
|
|
||
| // Increment volumeIO stats here. | ||
| volumeIOStats.incWriteTime(Time.monotonicNow() - writeTimeStart); | ||
| volumeIOStats.incWriteOpCount(); | ||
| volumeIOStats.incWriteBytes(info.getLen()); | ||
| break; | ||
| case COMMIT_DATA: | ||
| updateContainerWriteStats(container, info, false); | ||
| break; | ||
| case COMBINED: | ||
| updateContainerWriteStats(container, info, false); | ||
| break; | ||
| default: | ||
| throw new IOException("Can not identify write operation."); | ||
| } | ||
| } catch (IOException ex) { | ||
| LOG.error("write data failed. error: {}", ex); | ||
| throw new StorageContainerException("Internal error: ", ex, | ||
| CONTAINER_INTERNAL_ERROR); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * return a zero-filled buffer. | ||
| * | ||
| * @param container - Container for the chunk | ||
| * @param blockID - ID of the block. | ||
| * @param info - ChunkInfo. | ||
| * @param dispatcherContext dispatcher context info. | ||
| * @return byte array | ||
| * TODO: Right now we do not support partial reads and writes of chunks. | ||
| * TODO: Explore if we need to do that for ozone. | ||
| */ | ||
| @Override | ||
| public byte[] readChunk(Container container, BlockID blockID, ChunkInfo info, | ||
| DispatcherContext dispatcherContext) { | ||
|
|
||
| long readStartTime = Time.monotonicNow(); | ||
|
|
||
| KeyValueContainerData containerData = (KeyValueContainerData) container | ||
| .getContainerData(); | ||
| ByteBuffer data; | ||
| HddsVolume volume = containerData.getVolume(); | ||
| VolumeIOStats volumeIOStats = volume.getVolumeIOStats(); | ||
|
|
||
| data = ByteBuffer.allocate((int) info.getLen()); | ||
|
|
||
| // Increment volumeIO stats here. | ||
| volumeIOStats.incReadTime(Time.monotonicNow() - readStartTime); | ||
| volumeIOStats.incReadOpCount(); | ||
| volumeIOStats.incReadBytes(info.getLen()); | ||
|
|
||
| return data.array(); | ||
| } | ||
|
|
||
| /** | ||
| * Delete a given chunk - Do nothing except stats. | ||
| * | ||
| * @param container - Container for the chunk | ||
| * @param blockID - ID of the block | ||
| * @param info - Chunk Info | ||
| */ | ||
| @Override | ||
| public void deleteChunk(Container container, BlockID blockID, | ||
| ChunkInfo info) { | ||
| Preconditions.checkNotNull(blockID, "Block ID cannot be null."); | ||
| KeyValueContainerData containerData = | ||
| (KeyValueContainerData) container.getContainerData(); | ||
|
|
||
| if (info.getOffset() == 0) { | ||
| containerData.decrBytesUsed(info.getLen()); | ||
| } | ||
| } | ||
| } |
90 changes: 90 additions & 0 deletions
90
...ce/src/main/java/org/apache/hadoop/ozone/container/keyvalue/impl/ChunkManagerFactory.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,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 com.google.common.base.Preconditions; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hdds.HddsConfigKeys; | ||
| import org.apache.hadoop.ozone.container.keyvalue.interfaces.ChunkManager; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_CONTAINER_PERSISTDATA; | ||
| import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_CONTAINER_PERSISTDATA_DEFAULT; | ||
|
|
||
| /** | ||
| * Select an appropriate ChunkManager implementation as per config setting. | ||
| * Ozone ChunkManager is a Singleton | ||
| */ | ||
| public final class ChunkManagerFactory { | ||
| static final Logger LOG = LoggerFactory.getLogger(ChunkManagerFactory.class); | ||
|
|
||
| private static volatile ChunkManager instance = null; | ||
| private static boolean syncChunks = false; | ||
|
|
||
| private ChunkManagerFactory() { | ||
| } | ||
|
|
||
| public static ChunkManager getChunkManager(Configuration config, | ||
| boolean sync) { | ||
| if (instance == null) { | ||
| synchronized (ChunkManagerFactory.class) { | ||
| if (instance == null) { | ||
| instance = createChunkManager(config, sync); | ||
| syncChunks = sync; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Preconditions.checkArgument((syncChunks == sync), | ||
| "value of sync conflicts with previous invocation"); | ||
| return instance; | ||
| } | ||
|
|
||
| private static ChunkManager createChunkManager(Configuration config, | ||
| boolean sync) { | ||
| ChunkManager manager = null; | ||
| boolean persist = config.getBoolean(HDDS_CONTAINER_PERSISTDATA, | ||
| HDDS_CONTAINER_PERSISTDATA_DEFAULT); | ||
|
|
||
| if (!persist) { | ||
| boolean scrubber = config.getBoolean( | ||
| HddsConfigKeys.HDDS_CONTAINERSCRUB_ENABLED, | ||
| HddsConfigKeys.HDDS_CONTAINERSCRUB_ENABLED_DEFAULT); | ||
| if (scrubber) { | ||
| // Data Scrubber needs to be disabled for non-persistent chunks. | ||
| LOG.warn("Failed to set " + HDDS_CONTAINER_PERSISTDATA + " to false." | ||
| + " Please set " + HddsConfigKeys.HDDS_CONTAINERSCRUB_ENABLED | ||
| + " also to false to enable non-persistent containers."); | ||
| persist = true; | ||
| } | ||
| } | ||
|
|
||
| if (persist) { | ||
| manager = new ChunkManagerImpl(sync); | ||
| } else { | ||
| LOG.warn(HDDS_CONTAINER_PERSISTDATA | ||
supratimdeka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| + " is set to false. This should be used only for testing." | ||
| + " All user data will be discarded."); | ||
| manager = new ChunkManagerDummyImpl(sync); | ||
| } | ||
|
|
||
| return manager; | ||
| } | ||
| } | ||
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
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.