Skip to content

Commit

Permalink
HBASE-28861 Use hasReferences() api of SFT in RegionSplitter and remo…
Browse files Browse the repository at this point in the history
…ve Reference.read(), HRegionFS.hasReferences() (#6428)

Signed-off-by: Andrew Purtell <[email protected]>
Co-authored-by: Prathyusha Garre <[email protected]>
  • Loading branch information
2 people authored and mnpoonia committed Jan 24, 2025
1 parent 71e67d5 commit bba911a
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 58 deletions.
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 @@ -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

0 comments on commit bba911a

Please sign in to comment.