-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…2253) ### What changes were proposed in this pull request? - Introduce a factory to create specific LocalStorageManager by config. - Introduce multiply disk LocalStorageManager. ### Why are the changes needed? Fix: #436 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? - Existing UTs and new added UT - Tested on our pressure test cluster. - new client -> old server ✓ - new client -> new server ✓ - old client -> new server ❌, so we have to upgraded client first, than upgrade the servers
- Loading branch information
1 parent
54611f3
commit b7d391c
Showing
40 changed files
with
1,526 additions
and
248 deletions.
There are no files selected for viewing
142 changes: 142 additions & 0 deletions
142
common/src/main/java/io/netty/util/CompositeFileRegion.java
This file contains 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,142 @@ | ||
/* | ||
* 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 io.netty.util; | ||
|
||
import java.io.IOException; | ||
import java.nio.channels.WritableByteChannel; | ||
|
||
import io.netty.channel.FileRegion; | ||
|
||
import org.apache.uniffle.common.netty.protocol.AbstractFileRegion; | ||
|
||
public class CompositeFileRegion extends AbstractFileRegion { | ||
private final FileRegion[] regions; | ||
private long totalSize = 0; | ||
private long bytesTransferred = 0; | ||
|
||
public CompositeFileRegion(FileRegion... regions) { | ||
this.regions = regions; | ||
for (FileRegion region : regions) { | ||
totalSize += region.count(); | ||
} | ||
} | ||
|
||
@Override | ||
public long position() { | ||
return bytesTransferred; | ||
} | ||
|
||
@Override | ||
public long count() { | ||
return totalSize; | ||
} | ||
|
||
@Override | ||
public long transferTo(WritableByteChannel target, long position) throws IOException { | ||
long totalBytesTransferred = 0; | ||
|
||
for (FileRegion region : regions) { | ||
if (position >= region.count()) { | ||
position -= region.count(); | ||
} else { | ||
long currentBytesTransferred = region.transferTo(target, position); | ||
totalBytesTransferred += currentBytesTransferred; | ||
bytesTransferred += currentBytesTransferred; | ||
|
||
if (currentBytesTransferred < region.count() - position) { | ||
break; | ||
} | ||
position = 0; | ||
} | ||
} | ||
|
||
return totalBytesTransferred; | ||
} | ||
|
||
@Override | ||
public long transferred() { | ||
return bytesTransferred; | ||
} | ||
|
||
@Override | ||
public AbstractFileRegion retain() { | ||
super.retain(); | ||
for (FileRegion region : regions) { | ||
region.retain(); | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public AbstractFileRegion retain(int increment) { | ||
super.retain(increment); | ||
for (FileRegion region : regions) { | ||
region.retain(increment); | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean release() { | ||
boolean released = super.release(); | ||
for (FileRegion region : regions) { | ||
if (!region.release()) { | ||
released = false; | ||
} | ||
} | ||
return released; | ||
} | ||
|
||
@Override | ||
public boolean release(int decrement) { | ||
boolean released = super.release(decrement); | ||
for (FileRegion region : regions) { | ||
if (!region.release(decrement)) { | ||
released = false; | ||
} | ||
} | ||
return released; | ||
} | ||
|
||
@Override | ||
protected void deallocate() { | ||
for (FileRegion region : regions) { | ||
if (region instanceof AbstractReferenceCounted) { | ||
((AbstractReferenceCounted) region).deallocate(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public AbstractFileRegion touch() { | ||
super.touch(); | ||
for (FileRegion region : regions) { | ||
region.touch(); | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public AbstractFileRegion touch(Object hint) { | ||
super.touch(hint); | ||
for (FileRegion region : regions) { | ||
region.touch(hint); | ||
} | ||
return this; | ||
} | ||
} |
This file contains 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 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 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
83 changes: 83 additions & 0 deletions
83
...n/src/main/java/org/apache/uniffle/common/netty/buffer/MultiFileSegmentManagedBuffer.java
This file contains 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,83 @@ | ||
/* | ||
* 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.uniffle.common.netty.buffer; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.Unpooled; | ||
import io.netty.channel.FileRegion; | ||
import io.netty.util.CompositeFileRegion; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** A wrapper of multiple {@link FileSegmentManagedBuffer}, used for combine shuffle index files. */ | ||
public class MultiFileSegmentManagedBuffer extends ManagedBuffer { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(MultiFileSegmentManagedBuffer.class); | ||
private final List<ManagedBuffer> managedBuffers; | ||
|
||
public MultiFileSegmentManagedBuffer(List<ManagedBuffer> managedBuffers) { | ||
this.managedBuffers = managedBuffers; | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return managedBuffers.stream().mapToInt(ManagedBuffer::size).sum(); | ||
} | ||
|
||
@Override | ||
public ByteBuf byteBuf() { | ||
return Unpooled.wrappedBuffer(this.nioByteBuffer()); | ||
} | ||
|
||
@Override | ||
public ByteBuffer nioByteBuffer() { | ||
ByteBuffer merged = ByteBuffer.allocate(size()); | ||
for (ManagedBuffer managedBuffer : managedBuffers) { | ||
ByteBuffer buffer = managedBuffer.nioByteBuffer(); | ||
merged.put(buffer.slice()); | ||
} | ||
merged.flip(); | ||
return merged; | ||
} | ||
|
||
@Override | ||
public ManagedBuffer retain() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public ManagedBuffer release() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Object convertToNetty() { | ||
List<FileRegion> fileRegions = new ArrayList<>(managedBuffers.size()); | ||
for (ManagedBuffer managedBuffer : managedBuffers) { | ||
Object object = managedBuffer.convertToNetty(); | ||
if (object instanceof FileRegion) { | ||
fileRegions.add((FileRegion) object); | ||
} | ||
} | ||
return new CompositeFileRegion(fileRegions.toArray(new FileRegion[0])); | ||
} | ||
} |
This file contains 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.