Skip to content

feat: remove filter #285

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 13 commits into from
Aug 26, 2020
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 @@ -204,6 +204,66 @@ public LoadINode loadINode(final long parentId, final String childName) {
return res;
}

public LoadINode loadINode(final String parentName, final String childName) {
LoadINode res = null;
try {
DatabaseConnection obj = Database.getInstance().getConnection();
String env = System.getenv("DATABASE");
if (env.equals("VOLT")) {
try {
VoltTable[] results =
obj.getVoltClient().callProcedure("LoadINodeV3", parentName, childName).getResults();
VoltTable result = results[0];
result.resetRowPosition();
while (result.advanceRow()) {
res =
new LoadINode(
result.getLong(0),
result.getString(1),
result.getLong(2),
result.getString(3),
result.getLong(4),
result.getLong(5),
result.getLong(6),
result.getLong(7));
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
Connection conn = obj.getConnection();
String sql =
"SELECT parent, parentName, id, name, permission, modificationTime, accessTime, header FROM inodes WHERE parentName = ? AND name = ?;";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, parentName);
pst.setString(2, childName);
ResultSet rs = pst.executeQuery();
while (rs.next()) {
res =
new LoadINode(
rs.getLong(1),
rs.getString(2),
rs.getLong(3),
rs.getString(4),
rs.getLong(5),
rs.getLong(6),
rs.getLong(7),
rs.getLong(8));
}
rs.close();
pst.close();
}
Database.getInstance().retConnection(obj);
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}

if (LOG.isInfoEnabled()) {
LOG.info("Load INode [GET]: (" + parentName + ", " + childName + ")");
}
return res;
}

public static boolean checkInodeExistence(final long parentId, final String childName) {
boolean exist = false;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ static GetBlockLocationsResult getBlockLocations(
final INodesInPath iip = fsd.resolvePath(pc, src, DirOp.READ);
src = iip.getPath();
final INodeFile inode = INodeFile.valueOf(iip.getLastINode(), src);
if (iip.getLastINode() == null) {
iip.setLastINode(inode);
}
if (fsd.isPermissionEnabled()) {
fsd.checkPathAccess(pc, iip, FsAction.READ);
fsd.checkUnreadableBySuperuser(pc, iip);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public enum DirOp {
}
}

initFilterPool();
// initFilterPool();
}

public boolean isLocalNN() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public INodeDirectory(long id) {
public INodeDirectory(INodeDirectory other, boolean adopt,
Feature... featuresToCopy) {
super(other);
filter = other.filter.copy();
// filter = other.filter.copy();
final ReadOnlyList<INode> children = other.getCurrentChildrenList();
if (adopt && children != null) {
for (INode child : children) {
Expand Down Expand Up @@ -557,11 +557,15 @@ public ReadOnlyList<INode> getChildrenList(final int snapshotId) {

public HashSet<String> getCurrentChildrenList2() {
if (children.isEmpty()) {
children = new HashSet<>(DatabaseINode.getChildrenNames(getId()));
children = new HashSet<>();
}
return children;
}

public void resetCurrentChildrenList() {
children = new HashSet<>(DatabaseINode.getChildrenNames(getId()));
}

private ReadOnlyList<INode> getCurrentChildrenList() {
if (children.isEmpty()) {
children = new HashSet<>(DatabaseINode.getChildrenNames(getId()));
Expand Down Expand Up @@ -639,10 +643,14 @@ public boolean removeChild(final INode child) {
public boolean addChild(INode node, final boolean setModTime,
final int latestSnapshotId) {

if (getFilter().mightContain(String.valueOf(getId()) + node.getLocalName())) {
if (DatabaseINode.checkInodeExistence(getId(), node.getLocalName())) {
return false;
}
// if (getFilter().mightContain(String.valueOf(getId()) + node.getLocalName())) {
// if (DatabaseINode.checkInodeExistence(getId(), node.getLocalName())) {
// return false;
// }
// }

if (getCurrentChildrenList2().contains(node.getLocalName())) {
return false;
}

if (isInLatestSnapshot(latestSnapshotId)) {
Expand Down Expand Up @@ -714,15 +722,19 @@ public void remoteRename(INode node, String oldName, String oldParent, String ne
if (child.isDirectory()) {
HashSet<String> childNames = ((INodeDirectory)child).getCurrentChildrenList2();
for (String cname : childNames) {
q.add(new ImmutablePair<>(child.getPath(), cname));
if (child.getId() == old_id) {
q.add(new ImmutablePair<>(getOldPath(oldParent, oldName), cname));
} else {
q.add(new ImmutablePair<>(child.getPath(), cname));
}
}
}

child.setId(child.getId() + 100000);
if (child.getId() != old_id) {
child.setParent(child.getParentId() + 100000);
child.setParentName(newParent + child.getParentName().substring(skip_id));
}
child.setId(child.getId() + 100000);

if (child.isDirectory()) {
// log: create new diretory
Expand Down Expand Up @@ -792,10 +804,11 @@ public boolean addChild(
}

INode inode = node;
children.add(name);
getFilter().put(String.valueOf(getId()) + name);
// getFilter().put(String.valueOf(getId()) + name);
getCurrentChildrenList2().add(name);
if (node.getParentId() != getId() || !node.getLocalName().equals(name)) {
node.getParent().getFilter().delete(String.valueOf(node.getParentId()) + node.getLocalName());
node.getParent().getCurrentChildrenList2().remove(node.getLocalName());
// node.getParent().getFilter().delete(String.valueOf(node.getParentId()) + node.getLocalName());

String oldParent = node.getParentName();
String oldName = node.getLocalName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.List;
import java.util.Set;

import org.apache.hadoop.hdfs.DFSUtil;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.fs.StorageType;
import org.apache.hadoop.fs.permission.PermissionStatus;
Expand Down Expand Up @@ -88,7 +89,44 @@ public static INodeFile valueOf(INode inode, String path, boolean acceptNull)
if (acceptNull) {
return null;
} else {
throw new FileNotFoundException("File does not exist: " + path);
byte[][] pathComponents = INode.getPathComponents(path);
FSDirectory fsd = FSDirectory.getInstance();
pathComponents = fsd.resolveComponents(pathComponents, fsd);
String parentStr = DFSUtil.byteArray2PathString(pathComponents, 0, pathComponents.length - 1);
String childStr = DFSUtil.byteArray2PathString(pathComponents, pathComponents.length - 1, 1);
DatabaseINode.LoadINode node = new DatabaseINode().loadINode(parentStr, childStr);
if (node == null) throw new FileNotFoundException("File does not exist: " + parentStr + ", " + childStr);
byte[] name = (node.name != null && node.name.length() > 0) ? DFSUtil.string2Bytes(node.name) : null;
if (node.header != 0L) {
inode = new INodeFile(node.id);
inode.asFile().setNumBlocks();
inode
.asFile()
.InitINodeFile(
node.parent,
node.id,
name,
node.permission,
node.modificationTime,
node.accessTime,
node.header,
node.parentName);
} else {
inode = new INodeDirectory(node.id);
inode
.asDirectory()
.InitINodeDirectory(
node.parent,
node.id,
name,
node.permission,
node.modificationTime,
node.accessTime,
node.header,
node.parentName);
inode.asDirectory().resetCurrentChildrenList();
}
INodeKeyedObjects.getCache().put(path, inode);
}
}
if (!inode.isFile()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ public INode get(String parentName, String childName) {
INode inode = INodeKeyedObjects.getCache().getIfPresent(path);
if (inode == null) {
INodeDirectory parent = INodeKeyedObjects.getCache().getIfPresent(parentName).asDirectory();
if (!parent.getFilter().mightContain(String.valueOf(parent.getId()) + childName)) {
if (!parent.getCurrentChildrenList2().contains(childName)) {
return null;
}
// if (!parent.getFilter().mightContain(String.valueOf(parent.getId()) + childName)) {
// return null;
// }
DatabaseINode.LoadINode node = new DatabaseINode().loadINode(parent.getId(), childName);
if (node == null) return null;
byte[] name = (node.name != null && node.name.length() > 0) ? DFSUtil.string2Bytes(node.name) : null;
Expand Down Expand Up @@ -91,6 +94,7 @@ public INode get(String parentName, String childName) {
node.accessTime,
node.header,
node.parentName);
inode.asDirectory().resetCurrentChildrenList();
}
INodeKeyedObjects.getCache().put(path, inode);
}
Expand All @@ -104,9 +108,12 @@ public boolean find(INodeFile file) {
}

INodeDirectory parent = file.getParent();
if (parent.getFilter().mightContain(String.valueOf(parent.getId()) + file.getLocalName())) {
if (parent.getCurrentChildrenList2().contains(file.getLocalName())) {
return true;
}
// if (parent.getFilter().mightContain(String.valueOf(parent.getId()) + file.getLocalName())) {
// return true;
// }

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ public INode getLastINode() {
return getINode(-1);
}

public void setLastINode(INode inode) {
inodes[inodes.length - 1] = inode;
}

byte[] getLastLocalName() {
return path[path.length - 1];
}
Expand Down
14 changes: 14 additions & 0 deletions voltdb/LoadINodeV3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import org.voltdb.*;

// https://docs.voltdb.com/tutorial/Part5.php
public class LoadINodeV3 extends VoltProcedure {

public final SQLStmt sql =
new SQLStmt(
"SELECT parent, parentName, id, name, permission, modificationTime, accessTime, header FROM inodes WHERE parentName = ? AND name = ?;");

public VoltTable[] run(String parentName, String childName) throws VoltAbortException {
voltQueueSQL(sql, parentName, childName);
return voltExecuteSQL();
}
}