Skip to content

HBASE-28861 Use hasReferences api of SFT in RegionSplitter and remove… #6428

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 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@
*/
package org.apache.hadoop.hbase.io;

import java.io.BufferedInputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import org.apache.commons.io.IOUtils;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
Expand Down Expand Up @@ -144,36 +140,6 @@ public Path write(final FileSystem fs, final Path p) throws IOException {
return p;
}

/**
* Read a Reference from FileSystem.
* @return New Reference made from passed <code>p</code>
*/
public static Reference read(final FileSystem fs, final Path p) throws IOException {
InputStream in = fs.open(p);
try {
// I need to be able to move back in the stream if this is not a pb serialization so I can
// do the Writable decoding instead.
in = in.markSupported() ? in : new BufferedInputStream(in);
int pblen = ProtobufUtil.lengthOfPBMagic();
in.mark(pblen);
byte[] pbuf = new byte[pblen];
IOUtils.readFully(in, pbuf, 0, pblen);
// WATCHOUT! Return in middle of function!!!
if (ProtobufUtil.isPBMagicPrefix(pbuf)) return convert(FSProtos.Reference.parseFrom(in));
// Else presume Writables. Need to reset the stream since it didn't start w/ pb.
// We won't bother rewriting thie Reference as a pb since Reference is transitory.
in.reset();
Reference r = new Reference();
DataInputStream dis = new DataInputStream(in);
// Set in = dis so it gets the close below in the finally on our way out.
in = dis;
r.readFields(dis);
return r;
} finally {
in.close();
}
}

public FSProtos.Reference convert() {
FSProtos.Reference.Builder builder = FSProtos.Reference.newBuilder();
builder.setRange(isTopFileRegion(getFileRegion())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,28 +313,6 @@ StoreFileInfo getStoreFileInfo(final String familyName, final String fileName,
familyName, new Path(familyDir, fileName), tracker);
}

/**
* Returns true if the specified family has reference files
* @param familyName Column Family Name
* @return true if family contains reference files
*/
public boolean hasReferences(final String familyName) throws IOException {
Path storeDir = getStoreDir(familyName);
FileStatus[] files = CommonFSUtils.listStatus(fs, storeDir);
if (files != null) {
for (FileStatus stat : files) {
if (stat.isDirectory()) {
continue;
}
if (StoreFileInfo.isReference(stat.getPath())) {
LOG.trace("Reference {}", stat.getPath());
return true;
}
}
}
return false;
}

/** Returns the set of families present on disk n */
public Collection<String> getFamilies() throws IOException {
FileStatus[] fds =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.regionserver.HRegionFileSystem;
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTracker;
import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -680,7 +682,9 @@ static LinkedList<Pair<byte[], byte[]>> splitScan(LinkedList<Pair<byte[], byte[]
// Check every Column Family for that region -- check does not have references.
boolean refFound = false;
for (ColumnFamilyDescriptor c : htd.getColumnFamilies()) {
if ((refFound = regionFs.hasReferences(c.getNameAsString()))) {
StoreFileTracker sft = StoreFileTrackerFactory
.create(regionFs.getFileSystem().getConf(), htd, c, regionFs);
if ((refFound = sft.hasReferences())) {
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -146,7 +145,6 @@ private HRegionFileSystem mockFileSystem(RegionInfo info, boolean hasReferenceFi
HRegionFileSystem mockSystem = mock(HRegionFileSystem.class);
doReturn(info).when(mockSystem).getRegionInfo();
doReturn(regionStoreDir).when(mockSystem).getStoreDir(FAMILY);
doReturn(hasReferenceFiles).when(mockSystem).hasReferences(anyString());
doReturn(fileSystem).when(mockSystem).getFileSystem();
return mockSystem;
}
Expand Down