break; // no more transactions
}
numEdits++;
switch (opcode) {
case OP_ADD: {
UTF8 name = new UTF8();
ArrayWritable aw = null;
Writable writables[];
// version 0 does not support per file replication
if (logVersion >= 0)
name.readFields(in); // read name only
else { // other versions do
// get name and replication
aw = new ArrayWritable(UTF8.class);
aw.readFields(in);
writables = aw.get();
if (writables.length != 2)
throw new IOException("Incorrect data fortmat. "
+ "Name & replication pair expected");
name = (UTF8) writables[0];
replication = Short.parseShort(
((UTF8)writables[1]).toString());
replication = adjustReplication(replication);
}
// get blocks
aw = new ArrayWritable(Block.class);
aw.readFields(in);
writables = aw.get();
Block blocks[] = new Block[writables.length];
System.arraycopy(writables, 0, blocks, 0, blocks.length);
// add to the file tree
fsDir.unprotectedAddFile(name, blocks, replication);
break;
}
case OP_SET_REPLICATION: {
UTF8 src = new UTF8();
UTF8 repl = new UTF8();
src.readFields(in);
repl.readFields(in);
replication = adjustReplication(fromLogReplication(repl));
fsDir.unprotectedSetReplication(src.toString(),
replication,
null);
break;
}
case OP_RENAME: {
UTF8 src = new UTF8();
UTF8 dst = new UTF8();
src.readFields(in);
dst.readFields(in);
fsDir.unprotectedRenameTo(src, dst);
break;
}
case OP_DELETE: {
UTF8 src = new UTF8();
src.readFields(in);
fsDir.unprotectedDelete(src);
break;
}
case OP_MKDIR: {
UTF8 src = new UTF8();
src.readFields(in);
fsDir.unprotectedMkdir(src.toString());
break;
}
case OP_DATANODE_ADD: {
if (logVersion > -3)
throw new IOException("Unexpected opcode " + opcode