Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4B531105AD for ; Tue, 4 Feb 2014 17:55:37 +0000 (UTC) Received: (qmail 27282 invoked by uid 500); 4 Feb 2014 17:55:19 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 26061 invoked by uid 500); 4 Feb 2014 17:54:45 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 25351 invoked by uid 99); 4 Feb 2014 17:54:30 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Feb 2014 17:54:30 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 43450824125; Tue, 4 Feb 2014 17:54:30 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: elserj@apache.org To: commits@accumulo.apache.org Date: Tue, 04 Feb 2014 17:54:37 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [08/48] ACCUMULO-2292 Massive amount of fixes for findbugs warnings. http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/trace/InstanceUserPassword.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/trace/InstanceUserPassword.java b/core/src/main/java/org/apache/accumulo/core/trace/InstanceUserPassword.java index e9cb439..dfda097 100644 --- a/core/src/main/java/org/apache/accumulo/core/trace/InstanceUserPassword.java +++ b/core/src/main/java/org/apache/accumulo/core/trace/InstanceUserPassword.java @@ -16,6 +16,7 @@ */ package org.apache.accumulo.core.trace; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.Instance; public class InstanceUserPassword { @@ -26,6 +27,6 @@ public class InstanceUserPassword { public InstanceUserPassword(Instance instance, String username, String password) { this.instance = instance; this.username = username; - this.password = password.getBytes(); + this.password = password.getBytes(Constants.UTF8); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/trace/SpanTree.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/trace/SpanTree.java b/core/src/main/java/org/apache/accumulo/core/trace/SpanTree.java index 2a5d72e..772a133 100644 --- a/core/src/main/java/org/apache/accumulo/core/trace/SpanTree.java +++ b/core/src/main/java/org/apache/accumulo/core/trace/SpanTree.java @@ -42,7 +42,7 @@ public class SpanTree { public Set visit(SpanTreeVisitor visitor) { Set visited = new HashSet(); - List root = parentChildren.get(new Long(Span.ROOT_SPAN_ID)); + List root = parentChildren.get(Long.valueOf(Span.ROOT_SPAN_ID)); if (root == null || root.isEmpty()) return visited; RemoteSpan rootSpan = nodes.get(root.iterator().next()); http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java b/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java index 43fa464..1315a9d 100644 --- a/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java +++ b/core/src/main/java/org/apache/accumulo/core/trace/ZooTraceClient.java @@ -22,8 +22,9 @@ import java.util.List; import java.util.Map; import java.util.Random; -import org.apache.accumulo.trace.instrument.receivers.SendSpansViaThrift; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.fate.zookeeper.ZooReader; +import org.apache.accumulo.trace.instrument.receivers.SendSpansViaThrift; import org.apache.log4j.Logger; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.WatchedEvent; @@ -73,7 +74,7 @@ public class ZooTraceClient extends SendSpansViaThrift implements Watcher { List hosts = new ArrayList(); for (String child : children) { byte[] data = zoo.getData(path + "/" + child, null); - hosts.add(new String(data)); + hosts.add(new String(data, Constants.UTF8)); } this.hosts.clear(); this.hosts.addAll(hosts); http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/ByteArrayBackedCharSequence.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/ByteArrayBackedCharSequence.java b/core/src/main/java/org/apache/accumulo/core/util/ByteArrayBackedCharSequence.java index f64b36c..e7fe974 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/ByteArrayBackedCharSequence.java +++ b/core/src/main/java/org/apache/accumulo/core/util/ByteArrayBackedCharSequence.java @@ -16,6 +16,7 @@ */ package org.apache.accumulo.core.util; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.data.ByteSequence; public class ByteArrayBackedCharSequence implements CharSequence { @@ -60,7 +61,7 @@ public class ByteArrayBackedCharSequence implements CharSequence { } public String toString() { - return new String(data, offset, len); + return new String(data, offset, len, Constants.UTF8); } public void set(ByteSequence bs) { http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/ByteArraySet.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/ByteArraySet.java b/core/src/main/java/org/apache/accumulo/core/util/ByteArraySet.java index 68f0ae5..8b71e6f 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/ByteArraySet.java +++ b/core/src/main/java/org/apache/accumulo/core/util/ByteArraySet.java @@ -22,6 +22,8 @@ import java.util.Collection; import java.util.List; import java.util.TreeSet; +import org.apache.accumulo.core.Constants; + public class ByteArraySet extends TreeSet { private static final long serialVersionUID = 1L; @@ -38,7 +40,7 @@ public class ByteArraySet extends TreeSet { public static ByteArraySet fromStrings(Collection c) { List lst = new ArrayList(); for (String s : c) - lst.add(s.getBytes()); + lst.add(s.getBytes(Constants.UTF8)); return new ByteArraySet(lst); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java b/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java index 807bc95..01f76b7 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java +++ b/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import org.apache.accumulo.core.Constants; import org.apache.hadoop.io.Text; public class ByteBufferUtil { @@ -60,6 +61,6 @@ public class ByteBufferUtil { } public static String toString(ByteBuffer bytes) { - return new String(bytes.array(), bytes.position(), bytes.remaining()); + return new String(bytes.array(), bytes.position(), bytes.remaining(), Constants.UTF8); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/Encoding.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/Encoding.java b/core/src/main/java/org/apache/accumulo/core/util/Encoding.java index 1c8cb5d..451d4d6 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/Encoding.java +++ b/core/src/main/java/org/apache/accumulo/core/util/Encoding.java @@ -16,13 +16,14 @@ */ package org.apache.accumulo.core.util; +import org.apache.accumulo.core.Constants; import org.apache.commons.codec.binary.Base64; import org.apache.hadoop.io.Text; public class Encoding { public static String encodeAsBase64FileName(Text data) { - String encodedRow = new String(Base64.encodeBase64(TextUtil.getBytes(data))); + String encodedRow = new String(Base64.encodeBase64(TextUtil.getBytes(data)), Constants.UTF8); encodedRow = encodedRow.replace('/', '_').replace('+', '-'); int index = encodedRow.length() - 1; @@ -39,7 +40,7 @@ public class Encoding { node = node.replace('_', '/').replace('-', '+'); - return Base64.decodeBase64(node.getBytes()); + return Base64.decodeBase64(node.getBytes(Constants.UTF8)); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/FastFormat.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/FastFormat.java b/core/src/main/java/org/apache/accumulo/core/util/FastFormat.java index 496ca95..8c3e416 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/FastFormat.java +++ b/core/src/main/java/org/apache/accumulo/core/util/FastFormat.java @@ -16,12 +16,14 @@ */ package org.apache.accumulo.core.util; +import org.apache.accumulo.core.Constants; + public class FastFormat { // this 7 to 8 times faster than String.format("%s%06d",prefix, num) public static byte[] toZeroPaddedString(long num, int width, int radix, byte[] prefix) { byte ret[] = new byte[width + prefix.length]; if (toZeroPaddedString(ret, 0, num, width, radix, prefix) != ret.length) - throw new RuntimeException(" Did not format to expected width " + num + " " + width + " " + radix + " " + new String(prefix)); + throw new RuntimeException(" Did not format to expected width " + num + " " + width + " " + radix + " " + new String(prefix, Constants.UTF8)); return ret; } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/Merge.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/Merge.java b/core/src/main/java/org/apache/accumulo/core/util/Merge.java index 5ec7a9a..b6cb07f 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/Merge.java +++ b/core/src/main/java/org/apache/accumulo/core/util/Merge.java @@ -233,7 +233,7 @@ public class Merge { Entry entry = iterator.next(); Key key = entry.getKey(); if (key.getColumnFamily().equals(Constants.METADATA_DATAFILE_COLUMN_FAMILY)) { - String[] sizeEntries = new String(entry.getValue().get()).split(","); + String[] sizeEntries = new String(entry.getValue().get(), Constants.UTF8).split(","); if (sizeEntries.length == 2) { tabletSize += Long.parseLong(sizeEntries[0]); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/MetadataTable.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/MetadataTable.java b/core/src/main/java/org/apache/accumulo/core/util/MetadataTable.java index e94ef35..fdc7eef 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/MetadataTable.java +++ b/core/src/main/java/org/apache/accumulo/core/util/MetadataTable.java @@ -61,7 +61,7 @@ public class MetadataTable { } public DataFileValue(byte[] encodedDFV) { - String[] ba = new String(encodedDFV).split(","); + String[] ba = new String(encodedDFV, Constants.UTF8).split(","); size = Long.parseLong(ba[0]); numEntries = Long.parseLong(ba[1]); @@ -90,8 +90,8 @@ public class MetadataTable { public byte[] encode() { if (time >= 0) - return ("" + size + "," + numEntries + "," + time).getBytes(); - return ("" + size + "," + numEntries).getBytes(); + return ("" + size + "," + numEntries + "," + time).getBytes(Constants.UTF8); + return ("" + size + "," + numEntries).getBytes(Constants.UTF8); } public boolean equals(Object o) { http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java b/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java index f78747e..45bbe00 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java +++ b/core/src/main/java/org/apache/accumulo/core/util/TextUtil.java @@ -43,7 +43,7 @@ public final class TextUtil { Text newText = new Text(); newText.append(text.getBytes(), 0, maxLen); String suffix = "... TRUNCATED"; - newText.append(suffix.getBytes(), 0, suffix.length()); + newText.append(suffix.getBytes(Constants.UTF8), 0, suffix.length()); return newText; } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java index 7efe5e6..656f2ae 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java @@ -16,9 +16,12 @@ */ package org.apache.accumulo.core.util.shell; +import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.InetAddress; import java.util.Arrays; @@ -437,7 +440,7 @@ public class Shell extends ShellOptions { ShellCompletor userCompletor = null; if (execFile != null) { - java.util.Scanner scanner = new java.util.Scanner(new File(execFile)); + java.util.Scanner scanner = new java.util.Scanner(new File(execFile), Constants.UTF8.name()); try { while (scanner.hasNextLine() && !hasExited()) { execCommand(scanner.nextLine(), true, isVerbose()); @@ -542,7 +545,7 @@ public class Shell extends ShellOptions { // Obtain the command from the command table sc = commandFactory.get(command); if (sc == null) { - reader.printString(String.format("Unknown command \"%s\". Enter \"help\" for a list possible commands.\n", command)); + reader.printString(String.format("Unknown command \"%s\". Enter \"help\" for a list possible commands.%n", command)); reader.flushConsole(); return; } @@ -805,7 +808,7 @@ public class Shell extends ShellOptions { PrintWriter writer; public PrintFile(String filename) throws FileNotFoundException { - writer = new PrintWriter(filename); + writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), Constants.UTF8))); } @Override @@ -940,7 +943,7 @@ public class Shell extends ShellOptions { } private final void printHelp(String usage, String description, Options opts, int width) { - PrintWriter pw = new PrintWriter(System.err); + PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.err, Constants.UTF8)); new HelpFormatter().printHelp(pw, width, usage, description, opts, 2, 5, null, true); pw.flush(); if (logErrorsToConsole && writer != null) { http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java index 44cbd35..6bd260c 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java @@ -19,6 +19,7 @@ package org.apache.accumulo.core.util.shell.commands; import java.io.File; import java.util.TreeSet; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.util.shell.Shell; import org.apache.accumulo.core.util.shell.Shell.Command; @@ -42,11 +43,11 @@ public class AddSplitsCommand extends Command { final String f = cl.getOptionValue(optSplitsFile.getOpt()); String line; - java.util.Scanner file = new java.util.Scanner(new File(f)); + java.util.Scanner file = new java.util.Scanner(new File(f), Constants.UTF8.name()); while (file.hasNextLine()) { line = file.nextLine(); if (!line.isEmpty()) { - splits.add(decode ? new Text(Base64.decodeBase64(line.getBytes())) : new Text(line)); + splits.add(decode ? new Text(Base64.decodeBase64(line.getBytes(Constants.UTF8))) : new Text(line)); } } } else { http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java index ae7854b..5266337 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AuthenticateCommand.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.Map; import java.util.Set; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.security.tokens.PasswordToken; @@ -37,7 +38,7 @@ public class AuthenticateCommand extends Command { shellState.getReader().printNewline(); return 0; } // user canceled - final byte[] password = p.getBytes(); + final byte[] password = p.getBytes(Constants.UTF8); final boolean valid = shellState.getConnector().securityOperations().authenticateUser(user, new PasswordToken(password)); shellState.getReader().printString((valid ? "V" : "Not v") + "alid\n"); return 0; http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java index c439909..b476ae4 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CreateTableCommand.java @@ -51,7 +51,6 @@ public class CreateTableCommand extends Command { private Option createTableOptEVC; private Option base64Opt; private Option createTableOptFormatter; - public static String testTable; public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, IOException, ClassNotFoundException { @@ -74,12 +73,12 @@ public class CreateTableCommand extends Command { final String f = cl.getOptionValue(createTableOptSplit.getOpt()); String line; - Scanner file = new Scanner(new File(f)); + Scanner file = new Scanner(new File(f), Constants.UTF8.name()); try { while (file.hasNextLine()) { line = file.nextLine(); if (!line.isEmpty()) - partitions.add(decode ? new Text(Base64.decodeBase64(line.getBytes())) : new Text(line)); + partitions.add(decode ? new Text(Base64.decodeBase64(line.getBytes(Constants.UTF8 ))) : new Text(line)); } } finally { file.close(); http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java index a9c409f..5fa5b10 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java @@ -19,6 +19,7 @@ package org.apache.accumulo.core.util.shell.commands; import java.io.File; import java.util.Scanner; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.util.shell.Shell; import org.apache.accumulo.core.util.shell.Shell.Command; import org.apache.commons.cli.CommandLine; @@ -35,7 +36,7 @@ public class ExecfileCommand extends Command { @Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception { - Scanner scanner = new Scanner(new File(cl.getArgs()[0])); + Scanner scanner = new Scanner(new File(cl.getArgs()[0]), Constants.UTF8.name()); try { while (scanner.hasNextLine()) { shellState.execCommand(scanner.nextLine(), true, cl.hasOption(verboseOption.getOpt())); http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java index 12c17cb..635d0ff 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java @@ -99,7 +99,7 @@ public class GetSplitsCommand extends Command { return null; } BinaryFormatter.getlength(text.getLength()); - return encode ? new String(Base64.encodeBase64(TextUtil.getBytes(text))) : BinaryFormatter.appendText(new StringBuilder(), text).toString(); + return encode ? new String(Base64.encodeBase64(TextUtil.getBytes(text)), Constants.UTF8) : BinaryFormatter.appendText(new StringBuilder(), text).toString(); } private static String obscuredTabletName(final KeyExtent extent) { @@ -112,7 +112,7 @@ public class GetSplitsCommand extends Command { if (extent.getEndRow() != null && extent.getEndRow().getLength() > 0) { digester.update(extent.getEndRow().getBytes(), 0, extent.getEndRow().getLength()); } - return new String(Base64.encodeBase64(digester.digest())); + return new String(Base64.encodeBase64(digester.digest()), Constants.UTF8); } @Override http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java index 1967dce..765fdc4 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HelpCommand.java @@ -91,7 +91,7 @@ public class HelpCommand extends Command { for (String cmd : cl.getArgs()) { final Command c = shellState.commandFactory.get(cmd); if (c == null) { - shellState.getReader().printString(String.format("Unknown command \"%s\". Enter \"help\" for a list possible commands.\n", cmd)); + shellState.getReader().printString(String.format("Unknown command \"%s\". Enter \"help\" for a list possible commands.%n", cmd)); } else { c.printHelp(shellState, numColumns); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HiddenCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HiddenCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HiddenCommand.java index 0413d73..41594ca 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HiddenCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HiddenCommand.java @@ -19,6 +19,7 @@ package org.apache.accumulo.core.util.shell.commands; import java.security.SecureRandom; import java.util.Random; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.util.shell.Shell; import org.apache.accumulo.core.util.shell.Shell.Command; import org.apache.accumulo.core.util.shell.ShellCommandException; @@ -42,7 +43,7 @@ public class HiddenCommand extends Command { shellState.getReader().printString( new String(Base64.decodeBase64(("ICAgICAgIC4tLS4KICAgICAgLyAvXCBcCiAgICAgKCAvLS1cICkKICAgICAuPl8gIF88LgogICAgLyB8ICd8ICcgXAog" + "ICAvICB8Xy58Xy4gIFwKICAvIC98ICAgICAgfFwgXAogfCB8IHwgfFwvfCB8IHwgfAogfF98IHwgfCAgfCB8IHxffAogICAgIC8gIF9fICBcCiAgICAvICAv" - + "ICBcICBcCiAgIC8gIC8gICAgXCAgXF8KIHwvICAvICAgICAgXCB8IHwKIHxfXy8gICAgICAgIFx8X3wK").getBytes()))); + + "ICBcICBcCiAgIC8gIC8gICAgXCAgXF8KIHwvICAvICAgICAgXCB8IHwKIHxfXy8gICAgICAgIFx8X3wK").getBytes(Constants.UTF8)), Constants.UTF8)); shellState.getReader().printNewline(); } else { throw new ShellCommandException(ErrorCode.UNRECOGNIZED_COMMAND, getName()); http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java index 6de8c39..43dc64f 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/HistoryCommand.java @@ -17,12 +17,16 @@ package org.apache.accumulo.core.util.shell.commands; import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.io.PrintWriter; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.util.shell.Shell; import org.apache.accumulo.core.util.shell.Shell.Command; import org.apache.commons.cli.CommandLine; @@ -43,22 +47,25 @@ public class HistoryCommand extends Command { int counter = 0; if (cl.hasOption(clearHist.getOpt())) { - + PrintWriter out = null; try { - - final FileWriter outFile = new FileWriter(histDir + "/shell_history.txt"); - final PrintWriter out = new PrintWriter(outFile); - out.close(); - - } catch (IOException e) { - + FileOutputStream file = new FileOutputStream(histDir + "/shell_history.txt"); + final BufferedWriter fileWriter = new BufferedWriter(new OutputStreamWriter(file, Constants.UTF8)); + out = new PrintWriter(fileWriter); + } catch (FileNotFoundException e) { e.printStackTrace(); + } finally { + // If the file existed, closing the + if (null != out) { + out.close(); + } } } else { + BufferedReader in = null; try { - final BufferedReader in = new BufferedReader(new FileReader(histDir + "/shell_history.txt")); + in = new BufferedReader(new InputStreamReader(new FileInputStream(histDir + "/shell_history.txt"), Constants.UTF8)); String Line; try { Line = in.readLine(); @@ -74,6 +81,10 @@ public class HistoryCommand extends Command { } catch (FileNotFoundException e) { e.printStackTrace(); + } finally { + if (null != in) { + in.close(); + } } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java index 754e033..6001956 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java @@ -59,8 +59,10 @@ public class ListIterCommand extends Command { throw new IllegalArgumentException("You must select at least one scope to configure"); } final StringBuilder sb = new StringBuilder("-\n"); - for (String name : iterators.keySet()) { - for (IteratorScope scope : iterators.get(name)) { + for (Entry> entry : iterators.entrySet()) { + final String name = entry.getKey(); + final EnumSet scopes = entry.getValue(); + for (IteratorScope scope : scopes) { if (cl.hasOption(scopeOpts.get(scope).getOpt())) { IteratorSetting setting = shellState.getConnector().tableOperations().getIteratorSetting(tableName, name, scope); sb.append("- Iterator ").append(setting.getName()).append(", ").append(scope).append(" scope options:\n"); http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java index aba9dd3..7a3be0c 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/PasswdCommand.java @@ -18,6 +18,7 @@ package org.apache.accumulo.core.util.shell.commands; import java.io.IOException; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode; @@ -63,7 +64,7 @@ public class PasswdCommand extends Command { if (!password.equals(passwordConfirm)) { throw new IllegalArgumentException("Passwords do not match"); } - byte[] pass = password.getBytes(); + byte[] pass = password.getBytes(Constants.UTF8); shellState.getConnector().securityOperations().changeLocalUserPassword(user, new PasswordToken(pass)); // update the current credentials if the password changed was for // the current user http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuotedStringTokenizer.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuotedStringTokenizer.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuotedStringTokenizer.java index 6872d89..b670d9d 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuotedStringTokenizer.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/QuotedStringTokenizer.java @@ -20,6 +20,7 @@ import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Iterator; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.util.BadArgumentException; import org.apache.accumulo.core.util.shell.Shell; @@ -57,7 +58,7 @@ public class QuotedStringTokenizer implements Iterable { final byte[] token = new byte[input.length()]; int tokenLength = 0; - final byte[] inputBytes = input.getBytes(); + final byte[] inputBytes = input.getBytes(Constants.UTF8); for (int i = 0; i < input.length(); ++i) { final char ch = input.charAt(i); http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java index 26e38e6..275b1b0 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java @@ -222,8 +222,6 @@ public class SetIterCommand extends Command { if (input == null) { reader.printNewline(); throw new IOException("Input stream closed"); - } else { - input = new String(input); } // Places all Parameters and Values into the LocalOptions, even if the value is "". // This allows us to check for "" values when setting the iterators and allows us to remove @@ -244,8 +242,6 @@ public class SetIterCommand extends Command { if (input == null) { reader.printNewline(); throw new IOException("Input stream closed"); - } else { - input = new String(input); } if (input.length() == 0) http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java index 864b5f3..221beaf 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserCommand.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.Map; import java.util.Set; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.security.tokens.PasswordToken; @@ -43,7 +44,7 @@ public class UserCommand extends Command { shellState.getReader().printNewline(); return 0; } // user canceled - pass = p.getBytes(); + pass = p.getBytes(Constants.UTF8); shellState.updateUser(user, new PasswordToken(pass)); return 0; } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserPermissionsCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserPermissionsCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserPermissionsCommand.java index 8da9742..ce0eed9 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserPermissionsCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/UserPermissionsCommand.java @@ -30,7 +30,6 @@ import org.apache.commons.cli.Options; public class UserPermissionsCommand extends Command { private Option userOpt; - private static int runOnce = 0; @Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException { @@ -46,20 +45,21 @@ public class UserPermissionsCommand extends Command { } shellState.getReader().printNewline(); + boolean runOnce = true; for (String t : shellState.getConnector().tableOperations().list()) { delim = ""; for (TablePermission p : TablePermission.values()) { if (shellState.getConnector().securityOperations().hasTablePermission(user, t, p) && p != null) { - if (runOnce == 0) { + if (runOnce) { shellState.getReader().printString("\nTable permissions (" + t + "): "); - runOnce++; + runOnce = false; } shellState.getReader().printString(delim + "Table." + p.name()); delim = ", "; } } - runOnce = 0; + runOnce = true; } shellState.getReader().printNewline(); return 0; http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java ---------------------------------------------------------------------- diff --git a/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java b/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java index bc6874f..0162466 100644 --- a/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java +++ b/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java @@ -16,6 +16,7 @@ */ package org.apache.accumulo.fate; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -33,6 +34,8 @@ import org.apache.zookeeper.KeeperException; * A utility to administer FATE operations */ public class AdminUtil { + private static final Charset UTF8 = Charset.forName("UTF-8"); + public void print(ZooStore zs, IZooReaderWriter zk, String lockPath) throws KeeperException, InterruptedException { Map> heldLocks = new HashMap>(); Map> waitingLocks = new HashMap>(); @@ -51,7 +54,7 @@ public class AdminUtil { for (String node : lockNodes) { try { byte[] data = zk.getData(lockPath + "/" + id + "/" + node, null); - String lda[] = new String(data).split(":"); + String lda[] = new String(data, UTF8).split(":"); if (lda[0].charAt(0) == 'W') sawWriteLock = true; @@ -129,22 +132,30 @@ public class AdminUtil { } } - public void prepDelete(ZooStore zs, IZooReaderWriter zk, String path, String txidStr) { - checkGlobalLock(zk, path); + public boolean prepDelete(ZooStore zs, IZooReaderWriter zk, String path, String txidStr) { + if (!checkGlobalLock(zk, path)) { + return false; + } long txid = Long.parseLong(txidStr, 16); zs.reserve(txid); zs.delete(txid); zs.unreserve(txid, 0); + + return true; } - public void prepFail(ZooStore zs, IZooReaderWriter zk, String path, String txidStr) { - checkGlobalLock(zk, path); + public boolean prepFail(ZooStore zs, IZooReaderWriter zk, String path, String txidStr) { + if (!checkGlobalLock(zk, path)) { + return false; + } long txid = Long.parseLong(txidStr, 16); zs.reserve(txid); zs.setStatus(txid, TStatus.FAILED_IN_PROGRESS); zs.unreserve(txid, 0); + + return true; } public void deleteLocks(ZooStore zs, IZooReaderWriter zk, String path, String txidStr) throws KeeperException, InterruptedException { @@ -156,25 +167,27 @@ public class AdminUtil { for (String node : lockNodes) { String lockPath = path + "/" + id + "/" + node; byte[] data = zk.getData(path + "/" + id + "/" + node, null); - String lda[] = new String(data).split(":"); + String lda[] = new String(data, UTF8).split(":"); if (lda[1].equals(txidStr)) zk.recursiveDelete(lockPath, NodeMissingPolicy.SKIP); } } } - public void checkGlobalLock(IZooReaderWriter zk, String path) { + public boolean checkGlobalLock(IZooReaderWriter zk, String path) { try { if (ZooLock.getLockData(zk.getZooKeeper(), path) != null) { System.err.println("ERROR: Master lock is held, not running"); - System.exit(-1); + return false; } } catch (KeeperException e) { System.err.println("ERROR: Could not read master lock, not running " + e.getMessage()); - System.exit(-1); + return false; } catch (InterruptedException e) { System.err.println("ERROR: Could not read master lock, not running" + e.getMessage()); - System.exit(-1); + return false; } + + return true; } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/fate/src/main/java/org/apache/accumulo/fate/AgeOffStore.java ---------------------------------------------------------------------- diff --git a/fate/src/main/java/org/apache/accumulo/fate/AgeOffStore.java b/fate/src/main/java/org/apache/accumulo/fate/AgeOffStore.java index 3f52e70..f90c3a2 100644 --- a/fate/src/main/java/org/apache/accumulo/fate/AgeOffStore.java +++ b/fate/src/main/java/org/apache/accumulo/fate/AgeOffStore.java @@ -126,6 +126,7 @@ public class AgeOffStore implements TStore { case FAILED: case SUCCESSFUL: addCandidate(txid); + break; default: break; } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/fate/src/main/java/org/apache/accumulo/fate/Fate.java ---------------------------------------------------------------------- diff --git a/fate/src/main/java/org/apache/accumulo/fate/Fate.java b/fate/src/main/java/org/apache/accumulo/fate/Fate.java index 670154e..9d24b0b 100644 --- a/fate/src/main/java/org/apache/accumulo/fate/Fate.java +++ b/fate/src/main/java/org/apache/accumulo/fate/Fate.java @@ -170,7 +170,7 @@ public class Fate { } if (autoCleanUp) - store.setProperty(tid, AUTO_CLEAN_PROP, new Boolean(autoCleanUp)); + store.setProperty(tid, AUTO_CLEAN_PROP, Boolean.valueOf(autoCleanUp)); store.setProperty(tid, DEBUG_PROP, repo.getDescription()); http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java ---------------------------------------------------------------------- diff --git a/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java b/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java index c78dcc1..5fc1858 100644 --- a/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java +++ b/fate/src/main/java/org/apache/accumulo/fate/ZooStore.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.nio.charset.Charset; import java.security.SecureRandom; import java.util.ArrayList; import java.util.Collections; @@ -44,6 +45,7 @@ import org.apache.zookeeper.KeeperException.NodeExistsException; //TODO document zookeeper layout - ACCUMULO-1298 public class ZooStore implements TStore { + private static final Charset UTF8 = Charset.forName("UTF-8"); private String path; private IZooReaderWriter zk; @@ -103,7 +105,7 @@ public class ZooStore implements TStore { try { // looking at the code for SecureRandom, it appears to be thread safe long tid = idgenerator.nextLong() & 0x7fffffffffffffffl; - zk.putPersistentData(getTXPath(tid), TStatus.NEW.name().getBytes(), NodeExistsPolicy.FAIL); + zk.putPersistentData(getTXPath(tid), TStatus.NEW.name().getBytes(UTF8), NodeExistsPolicy.FAIL); return tid; } catch (NodeExistsException nee) { // exist, so just try another random # @@ -157,7 +159,7 @@ public class ZooStore implements TStore { // have reserved id, status should not change try { - TStatus status = TStatus.valueOf(new String(zk.getData(path + "/" + txdir, null))); + TStatus status = TStatus.valueOf(new String(zk.getData(path + "/" + txdir, null), UTF8)); if (status == TStatus.IN_PROGRESS || status == TStatus.FAILED_IN_PROGRESS) { return tid; } else { @@ -319,7 +321,7 @@ public class ZooStore implements TStore { private TStatus _getStatus(long tid) { try { - return TStatus.valueOf(new String(zk.getData(getTXPath(tid), null))); + return TStatus.valueOf(new String(zk.getData(getTXPath(tid), null), UTF8)); } catch (NoNodeException nne) { return TStatus.UNKNOWN; } catch (Exception e) { @@ -362,7 +364,7 @@ public class ZooStore implements TStore { verifyReserved(tid); try { - zk.putPersistentData(getTXPath(tid), status.name().getBytes(), NodeExistsPolicy.OVERWRITE); + zk.putPersistentData(getTXPath(tid), status.name().getBytes(UTF8), NodeExistsPolicy.OVERWRITE); } catch (Exception e) { throw new RuntimeException(e); } @@ -390,7 +392,7 @@ public class ZooStore implements TStore { try { if (so instanceof String) { - zk.putPersistentData(getTXPath(tid) + "/prop_" + prop, ("S " + so).getBytes(), NodeExistsPolicy.OVERWRITE); + zk.putPersistentData(getTXPath(tid) + "/prop_" + prop, ("S " + so).getBytes(UTF8), NodeExistsPolicy.OVERWRITE); } else { byte[] sera = serialize(so); byte[] data = new byte[sera.length + 2]; @@ -416,7 +418,7 @@ public class ZooStore implements TStore { System.arraycopy(data, 2, sera, 0, sera.length); return (Serializable) deserialize(sera); } else if (data[0] == 'S') { - return new String(data, 2, data.length - 2); + return new String(data, 2, data.length - 2, UTF8); } else { throw new IllegalStateException("Bad property data " + prop); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/fate/src/main/java/org/apache/accumulo/fate/zookeeper/DistributedReadWriteLock.java ---------------------------------------------------------------------- diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/DistributedReadWriteLock.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/DistributedReadWriteLock.java index a9e4f1e..cdf86c0 100644 --- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/DistributedReadWriteLock.java +++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/DistributedReadWriteLock.java @@ -16,6 +16,7 @@ */ package org.apache.accumulo.fate.zookeeper; +import java.nio.charset.Charset; import java.util.Arrays; import java.util.Iterator; import java.util.Map.Entry; @@ -31,6 +32,7 @@ import org.apache.log4j.Logger; // A ReadWriteLock that can be implemented in ZooKeeper. Features the ability to store data // with the lock, and recover the lock using that data to find the lock. public class DistributedReadWriteLock implements java.util.concurrent.locks.ReadWriteLock { + private static final Charset UTF8 = Charset.forName("UTF-8"); static enum LockType { READ, WRITE, @@ -58,7 +60,7 @@ public class DistributedReadWriteLock implements java.util.concurrent.locks.Read if (split == -1) throw new IllegalArgumentException(); - this.type = LockType.valueOf(new String(lockData, 0, split)); + this.type = LockType.valueOf(new String(lockData, 0, split, UTF8)); this.userData = Arrays.copyOfRange(lockData, split + 1, lockData.length); } @@ -71,7 +73,7 @@ public class DistributedReadWriteLock implements java.util.concurrent.locks.Read } public byte[] getLockData() { - byte typeBytes[] = type.name().getBytes(); + byte typeBytes[] = type.name().getBytes(UTF8); byte[] result = new byte[userData.length + 1 + typeBytes.length]; System.arraycopy(typeBytes, 0, result, 0, typeBytes.length); result[typeBytes.length] = ':'; @@ -143,7 +145,7 @@ public class DistributedReadWriteLock implements java.util.concurrent.locks.Read public boolean tryLock() { if (entry == -1) { entry = qlock.addEntry(new ParsedLock(this.lockType(), this.userData).getLockData()); - log.info("Added lock entry " + entry + " userData " + new String(this.userData) + " lockType " + lockType()); + log.info("Added lock entry " + entry + " userData " + new String(this.userData, UTF8) + " lockType " + lockType()); } SortedMap entries = qlock.getEarlierEntries(entry); for (Entry entry : entries.entrySet()) { @@ -153,7 +155,7 @@ public class DistributedReadWriteLock implements java.util.concurrent.locks.Read if (parsed.type == LockType.WRITE) return false; } - throw new IllegalStateException("Did not find our own lock in the queue: " + this.entry + " userData " + new String(this.userData) + " lockType " + throw new IllegalStateException("Did not find our own lock in the queue: " + this.entry + " userData " + new String(this.userData, UTF8) + " lockType " + lockType()); } @@ -175,7 +177,7 @@ public class DistributedReadWriteLock implements java.util.concurrent.locks.Read public void unlock() { if (entry == -1) return; - log.debug("Removing lock entry " + entry + " userData " + new String(this.userData) + " lockType " + lockType()); + log.debug("Removing lock entry " + entry + " userData " + new String(this.userData, UTF8) + " lockType " + lockType()); qlock.removeEntry(entry); entry = -1; } @@ -205,12 +207,12 @@ public class DistributedReadWriteLock implements java.util.concurrent.locks.Read public boolean tryLock() { if (entry == -1) { entry = qlock.addEntry(new ParsedLock(this.lockType(), this.userData).getLockData()); - log.info("Added lock entry " + entry + " userData " + new String(this.userData) + " lockType " + lockType()); + log.info("Added lock entry " + entry + " userData " + new String(this.userData, UTF8) + " lockType " + lockType()); } SortedMap entries = qlock.getEarlierEntries(entry); Iterator> iterator = entries.entrySet().iterator(); if (!iterator.hasNext()) - throw new IllegalStateException("Did not find our own lock in the queue: " + this.entry + " userData " + new String(this.userData) + " lockType " + throw new IllegalStateException("Did not find our own lock in the queue: " + this.entry + " userData " + new String(this.userData, UTF8) + " lockType " + lockType()); if (iterator.next().getKey().equals(entry)) return true; http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java ---------------------------------------------------------------------- diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java index e57b0b6..637c0e2 100644 --- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java +++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCache.java @@ -21,6 +21,7 @@ import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.nio.charset.Charset; import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.HashMap; @@ -42,6 +43,7 @@ import org.apache.zookeeper.data.Stat; */ public class ZooCache { private static final Logger log = Logger.getLogger(ZooCache.class); + private static final Charset UTF8 = Charset.forName("UTF-8"); private ZCacheWatcher watcher = new ZCacheWatcher(); private Watcher externalWatcher = null; @@ -221,10 +223,10 @@ public class ZooCache { throw new ConcurrentModificationException(); } if (log.isTraceEnabled()) - log.trace("zookeeper contained " + zPath + " " + (data == null ? null : new String(data))); + log.trace("zookeeper contained " + zPath + " " + (data == null ? null : new String(data, UTF8))); } if (log.isTraceEnabled()) - log.trace("putting " + zPath + " " + (data == null ? null : new String(data)) + " in cache"); + log.trace("putting " + zPath + " " + (data == null ? null : new String(data, UTF8)) + " in cache"); put(zPath, data, stat); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java ---------------------------------------------------------------------- diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java index 8772a83..86c3b88 100644 --- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java +++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooLock.java @@ -16,6 +16,7 @@ */ package org.apache.accumulo.fate.zookeeper; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -32,7 +33,7 @@ import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.data.Stat; public class ZooLock implements Watcher { - + private static final Charset UTF8 = Charset.forName("UTF-8"); protected static final Logger log = Logger.getLogger(ZooLock.class); public static final String LOCK_PREFIX = "zlock-"; @@ -346,9 +347,7 @@ public class ZooLock implements Watcher { watchingParent = false; if (event.getState() == KeeperState.Expired && lock != null) { - if (lock != null) { - lostLock(LockLossReason.SESSION_EXPIRED); - } + lostLock(LockLossReason.SESSION_EXPIRED); } else { try { // set the watch on the parent node again @@ -504,7 +503,7 @@ public class ZooLock implements Watcher { Stat stat = new Stat(); byte[] data = zk.getData(path + "/" + lockNode, stat); - if (lockData.equals(new String(data))) { + if (lockData.equals(new String(data, UTF8))) { zk.recursiveDelete(path + "/" + lockNode, stat.getVersion(), NodeMissingPolicy.FAIL); return true; } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java ---------------------------------------------------------------------- diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java index e938e88..f77260d 100644 --- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java +++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooReservation.java @@ -16,6 +16,8 @@ */ package org.apache.accumulo.fate.zookeeper; +import java.nio.charset.Charset; + import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeExistsPolicy; import org.apache.accumulo.fate.zookeeper.ZooUtil.NodeMissingPolicy; import org.apache.log4j.Logger; @@ -25,6 +27,7 @@ import org.apache.zookeeper.KeeperException.NodeExistsException; import org.apache.zookeeper.data.Stat; public class ZooReservation { + private static final Charset UTF8 = Charset.forName("UTF-8"); public static boolean attempt(IZooReaderWriter zk, String path, String reservationID, String debugInfo) throws KeeperException, InterruptedException { if (reservationID.contains(":")) @@ -32,7 +35,7 @@ public class ZooReservation { while (true) { try { - zk.putPersistentData(path, (reservationID + ":" + debugInfo).getBytes(), NodeExistsPolicy.FAIL); + zk.putPersistentData(path, (reservationID + ":" + debugInfo).getBytes(UTF8), NodeExistsPolicy.FAIL); return true; } catch (NodeExistsException nee) { Stat stat = new Stat(); @@ -43,9 +46,9 @@ public class ZooReservation { continue; } - String idInZoo = new String(zooData).split(":")[0]; + String idInZoo = new String(zooData, UTF8).split(":")[0]; - return idInZoo.equals(new String(reservationID)); + return idInZoo.equals(reservationID); } } @@ -63,10 +66,11 @@ public class ZooReservation { return; } - String idInZoo = new String(zooData).split(":")[0]; + String zooDataStr = new String(zooData, UTF8); + String idInZoo = zooDataStr.split(":")[0]; - if (!idInZoo.equals(new String(reservationID))) { - throw new IllegalStateException("Tried to release reservation " + path + " with data mismatch " + new String(reservationID) + " " + new String(zooData)); + if (!idInZoo.equals(reservationID)) { + throw new IllegalStateException("Tried to release reservation " + path + " with data mismatch " + reservationID + " " + zooDataStr); } zk.recursiveDelete(path, stat.getVersion(), NodeMissingPolicy.SKIP); http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java ---------------------------------------------------------------------- diff --git a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java index 13f6d08..de9729a 100644 --- a/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java +++ b/fate/src/main/java/org/apache/accumulo/fate/zookeeper/ZooSession.java @@ -18,8 +18,10 @@ package org.apache.accumulo.fate.zookeeper; import java.io.IOException; import java.net.UnknownHostException; +import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; + import org.apache.accumulo.fate.util.AddressUtil; import org.apache.accumulo.fate.util.UtilWaitThread; import org.apache.log4j.Logger; @@ -30,6 +32,7 @@ import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.ZooKeeper.States; public class ZooSession { + private static final Charset UTF8 = Charset.forName("UTF-8"); public static class ZooSessionShutdownException extends RuntimeException { @@ -50,7 +53,7 @@ public class ZooSession { private static Map sessions = new HashMap(); private static String sessionKey(String keepers, int timeout, String scheme, byte[] auth) { - return keepers + ":" + timeout + ":" + (scheme == null ? "" : scheme) + ":" + (auth == null ? "" : new String(auth)); + return keepers + ":" + timeout + ":" + (scheme == null ? "" : scheme) + ":" + (auth == null ? "" : new String(auth, UTF8)); } private static class ZooWatcher implements Watcher { http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java ---------------------------------------------------------------------- diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java index fc38f10..1b32997 100644 --- a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java +++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java @@ -19,10 +19,13 @@ package org.apache.accumulo.minicluster; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; +import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Writer; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -31,6 +34,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Properties; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.util.UtilWaitThread; import org.apache.accumulo.server.gc.SimpleGarbageCollector; @@ -62,8 +66,8 @@ public class MiniAccumuloCluster { */ public LogWriter(InputStream stream, File logFile) throws IOException { this.setDaemon(true); - this.in = new BufferedReader(new InputStreamReader(stream)); - out = new BufferedWriter(new FileWriter(logFile)); + this.in = new BufferedReader(new InputStreamReader(stream, Constants.UTF8)); + out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(logFile), Constants.UTF8)); SimpleTimer.getInstance().schedule(new Runnable() { @Override @@ -164,11 +168,11 @@ public class MiniAccumuloCluster { return process; } - private void appendProp(FileWriter fileWriter, Property key, String value, Map siteConfig) throws IOException { + private void appendProp(Writer fileWriter, Property key, String value, Map siteConfig) throws IOException { appendProp(fileWriter, key.getKey(), value, siteConfig); } - private void appendProp(FileWriter fileWriter, String key, String value, Map siteConfig) throws IOException { + private void appendProp(Writer fileWriter, String key, String value, Map siteConfig) throws IOException { if (!siteConfig.containsKey(key)) fileWriter.append("" + key + "" + value + "\n"); } @@ -234,7 +238,7 @@ public class MiniAccumuloCluster { File siteFile = new File(confDir, "accumulo-site.xml"); - FileWriter fileWriter = new FileWriter(siteFile); + OutputStreamWriter fileWriter = new OutputStreamWriter(new FileOutputStream(siteFile), Constants.UTF8); fileWriter.append("\n"); HashMap siteConfig = new HashMap(config.getSiteConfig()); @@ -275,7 +279,7 @@ public class MiniAccumuloCluster { fileWriter.close(); zooCfgFile = new File(confDir, "zoo.cfg"); - fileWriter = new FileWriter(zooCfgFile); + fileWriter = new OutputStreamWriter(new FileOutputStream(zooCfgFile), Constants.UTF8); // zookeeper uses Properties to read its config, so use that to write in order to properly escape things like Windows paths Properties zooCfg = new Properties(); http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java ---------------------------------------------------------------------- diff --git a/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java b/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java index 2a9a055..48e2906 100644 --- a/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java +++ b/proxy/src/main/java/org/apache/accumulo/proxy/ProxyServer.java @@ -25,6 +25,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import java.util.Set; import java.util.SortedSet; @@ -394,10 +395,10 @@ public class ProxyServer implements AccumuloProxy.Iface { try { Map> groups = getConnector(login).tableOperations().getLocalityGroups(tableName); Map> ret = new HashMap>(); - for (String key : groups.keySet()) { - ret.put(key, new HashSet()); - for (Text val : groups.get(key)) { - ret.get(key).add(val.toString()); + for (Entry> groupEntry : groups.entrySet()) { + ret.put(groupEntry.getKey(), new HashSet()); + for (Text val : groupEntry.getValue()) { + ret.get(groupEntry.getKey()).add(val.toString()); } } return ret; @@ -551,10 +552,10 @@ public class ProxyServer implements AccumuloProxy.Iface { org.apache.accumulo.proxy.thrift.TableNotFoundException, TException { try { Map> groups = new HashMap>(); - for (String key : groupStrings.keySet()) { - groups.put(key, new HashSet()); - for (String val : groupStrings.get(key)) { - groups.get(key).add(new Text(val)); + for (Entry> groupEntry : groupStrings.entrySet()) { + groups.put(groupEntry.getKey(), new HashSet()); + for (String val : groupEntry.getValue()) { + groups.get(groupEntry.getKey()).add(new Text(val)); } } getConnector(login).tableOperations().setLocalityGroups(tableName, groups); http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java ---------------------------------------------------------------------- diff --git a/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java b/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java index 4547684..6d6da7a 100644 --- a/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java +++ b/proxy/src/main/java/org/apache/accumulo/proxy/TestProxyClient.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.iterators.user.RegExFilter; import org.apache.accumulo.proxy.thrift.AccumuloProxy; @@ -73,7 +74,7 @@ public class TestProxyClient { System.out.println("Creating user: "); if (!tpc.proxy().listLocalUsers(login).contains("testuser")) { - tpc.proxy().createLocalUser(login, "testuser", ByteBuffer.wrap("testpass".getBytes())); + tpc.proxy().createLocalUser(login, "testuser", ByteBuffer.wrap("testpass".getBytes(Constants.UTF8))); } System.out.println("UserList: " + tpc.proxy().listLocalUsers(login)); @@ -99,9 +100,9 @@ public class TestProxyClient { Map> mutations = new HashMap>(); for (int i = 0; i < maxInserts; i++) { String result = String.format(format, i); - ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap(("cf" + i).getBytes()), ByteBuffer.wrap(("cq" + i).getBytes())); + ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap(("cf" + i).getBytes(Constants.UTF8)), ByteBuffer.wrap(("cq" + i).getBytes(Constants.UTF8))); update.setValue(Util.randStringBuffer(10)); - mutations.put(ByteBuffer.wrap(result.getBytes()), Collections.singletonList(update)); + mutations.put(ByteBuffer.wrap(result.getBytes(Constants.UTF8)), Collections.singletonList(update)); if (i % 1000 == 0) { tpc.proxy().updateAndFlush(login, testTable, mutations); @@ -125,10 +126,10 @@ public class TestProxyClient { for (int i = 0; i < maxInserts; i++) { String result = String.format(format, i); Key pkey = new Key(); - pkey.setRow(result.getBytes()); - ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap(("cf" + i).getBytes()), ByteBuffer.wrap(("cq" + i).getBytes())); + pkey.setRow(result.getBytes(Constants.UTF8)); + ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap(("cf" + i).getBytes(Constants.UTF8)), ByteBuffer.wrap(("cq" + i).getBytes(Constants.UTF8))); update.setValue(Util.randStringBuffer(10)); - mutations.put(ByteBuffer.wrap(result.getBytes()), Collections.singletonList(update)); + mutations.put(ByteBuffer.wrap(result.getBytes(Constants.UTF8)), Collections.singletonList(update)); tpc.proxy().update(writer, mutations); mutations.clear(); } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/proxy/src/main/java/org/apache/accumulo/proxy/Util.java ---------------------------------------------------------------------- diff --git a/proxy/src/main/java/org/apache/accumulo/proxy/Util.java b/proxy/src/main/java/org/apache/accumulo/proxy/Util.java index a166983..9f9c836 100644 --- a/proxy/src/main/java/org/apache/accumulo/proxy/Util.java +++ b/proxy/src/main/java/org/apache/accumulo/proxy/Util.java @@ -16,13 +16,14 @@ */ package org.apache.accumulo.proxy; -import org.apache.accumulo.proxy.thrift.IteratorSetting; -import org.apache.accumulo.proxy.thrift.Key; - import java.math.BigInteger; import java.nio.ByteBuffer; import java.util.Random; +import org.apache.accumulo.core.Constants; +import org.apache.accumulo.proxy.thrift.IteratorSetting; +import org.apache.accumulo.proxy.thrift.Key; + public class Util { private static Random random = new Random(0); @@ -32,7 +33,7 @@ public class Util { } public static ByteBuffer randStringBuffer(int numbytes) { - return ByteBuffer.wrap(new BigInteger(numbytes * 5, random).toString(32).getBytes()); + return ByteBuffer.wrap(new BigInteger(numbytes * 5, random).toString(32).getBytes(Constants.UTF8)); } public static IteratorSetting iteratorSetting2ProxyIteratorSetting(org.apache.accumulo.core.client.IteratorSetting is) { http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/server/src/main/java/org/apache/accumulo/server/Accumulo.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/accumulo/server/Accumulo.java b/server/src/main/java/org/apache/accumulo/server/Accumulo.java index ce99245..f4da33b 100644 --- a/server/src/main/java/org/apache/accumulo/server/Accumulo.java +++ b/server/src/main/java/org/apache/accumulo/server/Accumulo.java @@ -99,7 +99,7 @@ public class Accumulo { private void setMonitorPort() { try { - String port = new String(ZooReaderWriter.getInstance().getData(path, null)); + String port = new String(ZooReaderWriter.getInstance().getData(path, null), Constants.UTF8); System.setProperty("org.apache.accumulo.core.host.log.port", port); log.info("Changing monitor log4j port to "+port); doOnChange(); @@ -215,7 +215,7 @@ public class Accumulo { try { byte[] buffer = new byte[10]; int bytes = is.read(buffer); - String setting = new String(buffer, 0, bytes); + String setting = new String(buffer, 0, bytes, Constants.UTF8); setting = setting.trim(); if (bytes > 0 && Integer.parseInt(setting) > 10) { log.warn("System swappiness setting is greater than ten (" + setting + ") which can cause time-sensitive operations to be delayed. " http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java b/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java index 615dd38..3e0c63f 100644 --- a/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java +++ b/server/src/main/java/org/apache/accumulo/server/client/HdfsZooInstance.java @@ -86,13 +86,13 @@ public class HdfsZooInstance implements Instance { byte[] loc = zooCache.get(zRootLocPath); - opTimer.stop("Found root tablet at " + (loc == null ? null : new String(loc)) + " in %DURATION%"); + opTimer.stop("Found root tablet at " + (loc == null ? null : new String(loc, Constants.UTF8)) + " in %DURATION%"); if (loc == null) { return null; } - return new String(loc).split("\\|")[0]; + return new String(loc, Constants.UTF8).split("\\|")[0]; } @Override @@ -104,13 +104,13 @@ public class HdfsZooInstance implements Instance { byte[] loc = ZooLock.getLockData(zooCache, masterLocPath, null); - opTimer.stop("Found master at " + (loc == null ? null : new String(loc)) + " in %DURATION%"); + opTimer.stop("Found master at " + (loc == null ? null : new String(loc, Constants.UTF8)) + " in %DURATION%"); if (loc == null) { return Collections.emptyList(); } - return Collections.singletonList(new String(loc)); + return Collections.singletonList(new String(loc, Constants.UTF8)); } @Override http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/server/src/main/java/org/apache/accumulo/server/conf/TableConfiguration.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/accumulo/server/conf/TableConfiguration.java b/server/src/main/java/org/apache/accumulo/server/conf/TableConfiguration.java index 0a26b47..c5b6c18 100644 --- a/server/src/main/java/org/apache/accumulo/server/conf/TableConfiguration.java +++ b/server/src/main/java/org/apache/accumulo/server/conf/TableConfiguration.java @@ -121,7 +121,7 @@ public class TableConfiguration extends AccumuloConfiguration { byte[] v = getTablePropCache().get(zPath); String value = null; if (v != null) - value = new String(v); + value = new String(v, Constants.UTF8); return value; } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/server/src/main/java/org/apache/accumulo/server/conf/ZooConfiguration.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/accumulo/server/conf/ZooConfiguration.java b/server/src/main/java/org/apache/accumulo/server/conf/ZooConfiguration.java index d006498..15d7d8c 100644 --- a/server/src/main/java/org/apache/accumulo/server/conf/ZooConfiguration.java +++ b/server/src/main/java/org/apache/accumulo/server/conf/ZooConfiguration.java @@ -116,7 +116,7 @@ public class ZooConfiguration extends AccumuloConfiguration { byte[] v = propCache.get(zPath); String value = null; if (v != null) - value = new String(v); + value = new String(v, Constants.UTF8); return value; } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/server/src/main/java/org/apache/accumulo/server/constraints/MetadataConstraints.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/accumulo/server/constraints/MetadataConstraints.java b/server/src/main/java/org/apache/accumulo/server/constraints/MetadataConstraints.java index dfdb620..88c8593 100644 --- a/server/src/main/java/org/apache/accumulo/server/constraints/MetadataConstraints.java +++ b/server/src/main/java/org/apache/accumulo/server/constraints/MetadataConstraints.java @@ -186,7 +186,7 @@ public class MetadataConstraints implements Constraint { HashSet dataFiles = new HashSet(); HashSet loadedFiles = new HashSet(); - String tidString = new String(columnUpdate.getValue()); + String tidString = new String(columnUpdate.getValue(), Constants.UTF8); int otherTidCount = 0; for (ColumnUpdate update : mutation.getUpdates()) { @@ -199,7 +199,7 @@ public class MetadataConstraints implements Constraint { } else if (new Text(update.getColumnFamily()).equals(Constants.METADATA_BULKFILE_COLUMN_FAMILY)) { loadedFiles.add(new Text(update.getColumnQualifier())); - if (!new String(update.getValue()).equals(tidString)) { + if (!new String(update.getValue(), Constants.UTF8).equals(tidString)) { otherTidCount++; } } @@ -243,7 +243,7 @@ public class MetadataConstraints implements Constraint { } boolean lockHeld = false; - String lockId = new String(columnUpdate.getValue()); + String lockId = new String(columnUpdate.getValue(), Constants.UTF8); try { lockHeld = ZooLock.isLockHeld(zooCache, new ZooUtil.LockID(zooRoot, lockId)); @@ -260,9 +260,9 @@ public class MetadataConstraints implements Constraint { } if (violations != null) { - log.debug("violating metadata mutation : " + new String(mutation.getRow())); + log.debug("violating metadata mutation : " + new String(mutation.getRow(), Constants.UTF8)); for (ColumnUpdate update : mutation.getUpdates()) { - log.debug(" update: " + new String(update.getColumnFamily()) + ":" + new String(update.getColumnQualifier()) + " value " + (update.isDeleted() ? "[delete]" : new String(update.getValue()))); + log.debug(" update: " + new String(update.getColumnFamily(), Constants.UTF8) + ":" + new String(update.getColumnQualifier(), Constants.UTF8) + " value " + (update.isDeleted() ? "[delete]" : new String(update.getValue(), Constants.UTF8))); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/server/src/main/java/org/apache/accumulo/server/fate/Admin.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/accumulo/server/fate/Admin.java b/server/src/main/java/org/apache/accumulo/server/fate/Admin.java index c375981..4a5f0bc 100644 --- a/server/src/main/java/org/apache/accumulo/server/fate/Admin.java +++ b/server/src/main/java/org/apache/accumulo/server/fate/Admin.java @@ -79,9 +79,13 @@ public class Admin { ZooStore zs = new ZooStore(path, zk); if (jc.getParsedCommand().equals("fail")) { - admin.prepFail(zs, zk, masterPath, args[1]); + if (!admin.prepFail(zs, zk, masterPath, args[1])) { + System.exit(1); + } } else if (jc.getParsedCommand().equals("delete")) { - admin.prepDelete(zs, zk, masterPath, args[1]); + if (!admin.prepDelete(zs, zk, masterPath, args[1])) { + System.exit(1); + } admin.deleteLocks(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS, args[1]); } else if (jc.getParsedCommand().equals("print")) { admin.print(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS); http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/server/src/main/java/org/apache/accumulo/server/gc/SimpleGarbageCollector.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/accumulo/server/gc/SimpleGarbageCollector.java b/server/src/main/java/org/apache/accumulo/server/gc/SimpleGarbageCollector.java index af8e308..5627698 100644 --- a/server/src/main/java/org/apache/accumulo/server/gc/SimpleGarbageCollector.java +++ b/server/src/main/java/org/apache/accumulo/server/gc/SimpleGarbageCollector.java @@ -406,7 +406,7 @@ public class SimpleGarbageCollector implements Iface { while (true) { lock = new ZooLock(path); - if (lock.tryLock(lockWatcher, new ServerServices(address, Service.GC_CLIENT).toString().getBytes())) { + if (lock.tryLock(lockWatcher, new ServerServices(address, Service.GC_CLIENT).toString().getBytes(Constants.UTF8))) { break; } UtilWaitThread.sleep(1000); @@ -572,7 +572,7 @@ public class SimpleGarbageCollector implements Iface { if (cf.startsWith("../")) { delete = cf.substring(2); } else { - String table = new String(KeyExtent.tableOfMetadataRow(entry.getKey().getRow())); + String table = new String(KeyExtent.tableOfMetadataRow(entry.getKey().getRow()), Constants.UTF8); delete = "/" + table + cf; } // WARNING: This line is EXTREMELY IMPORTANT. @@ -584,7 +584,7 @@ public class SimpleGarbageCollector implements Iface { if (candidates.remove(path)) log.debug("Candidate was still in use in the METADATA table: " + path); } else if (Constants.METADATA_DIRECTORY_COLUMN.hasColumns(entry.getKey())) { - String table = new String(KeyExtent.tableOfMetadataRow(entry.getKey().getRow())); + String table = new String(KeyExtent.tableOfMetadataRow(entry.getKey().getRow()), Constants.UTF8); String delete = "/" + table + entry.getValue().toString(); if (candidates.remove(delete)) log.debug("Candidate was still in use in the METADATA table: " + delete); http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/server/src/main/java/org/apache/accumulo/server/logger/LogFileValue.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/accumulo/server/logger/LogFileValue.java b/server/src/main/java/org/apache/accumulo/server/logger/LogFileValue.java index 6019b18..25ad054 100644 --- a/server/src/main/java/org/apache/accumulo/server/logger/LogFileValue.java +++ b/server/src/main/java/org/apache/accumulo/server/logger/LogFileValue.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.data.ColumnUpdate; import org.apache.accumulo.core.data.Mutation; import org.apache.accumulo.server.data.ServerMutation; @@ -58,7 +59,7 @@ public class LogFileValue implements Writable { } private static String displayLabels(byte[] labels) { - String s = new String(labels); + String s = new String(labels, Constants.UTF8); s = s.replace("&", " & "); s = s.replace("|", " | "); return s; @@ -75,12 +76,13 @@ public class LogFileValue implements Writable { builder.append("..."); break; } - builder.append(" " + new String(m.getRow()) + "\n"); + builder.append(" ").append(new String(m.getRow(), Constants.UTF8)).append("\n"); for (ColumnUpdate update : m.getUpdates()) { String value = new String(update.getValue()); - builder.append(" " + new String(update.getColumnFamily()) + ":" + new String(update.getColumnQualifier()) + " " - + (update.hasTimestamp() ? "[user]:" : "[system]:") + update.getTimestamp() + " [" + displayLabels(update.getColumnVisibility()) + "] " - + (update.isDeleted() ? "" : value) + "\n"); + builder.append(" ").append(new String(update.getColumnFamily(), Constants.UTF8)).append(":") + .append(new String(update.getColumnQualifier(), Constants.UTF8)).append(" ").append(update.hasTimestamp() ? "[user]:" : "[system]:") + .append(update.getTimestamp()).append(" [").append(displayLabels(update.getColumnVisibility())).append("] ") + .append(update.isDeleted() ? "" : value).append("\n"); } } return builder.toString(); http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/server/src/main/java/org/apache/accumulo/server/logger/LogReader.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/accumulo/server/logger/LogReader.java b/server/src/main/java/org/apache/accumulo/server/logger/LogReader.java index ba9d694..4f9d33a 100644 --- a/server/src/main/java/org/apache/accumulo/server/logger/LogReader.java +++ b/server/src/main/java/org/apache/accumulo/server/logger/LogReader.java @@ -27,6 +27,7 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.cli.Help; import org.apache.accumulo.core.data.KeyExtent; import org.apache.accumulo.core.data.Mutation; @@ -167,7 +168,7 @@ public class LogReader { } if (rowMatcher != null) { - rowMatcher.reset(new String(m.getRow())); + rowMatcher.reset(new String(m.getRow(), Constants.UTF8)); if (rowMatcher.matches()) { found = true; break; http://git-wip-us.apache.org/repos/asf/accumulo/blob/b11a0361/server/src/main/java/org/apache/accumulo/server/master/LiveTServerSet.java ---------------------------------------------------------------------- diff --git a/server/src/main/java/org/apache/accumulo/server/master/LiveTServerSet.java b/server/src/main/java/org/apache/accumulo/server/master/LiveTServerSet.java index c038479..e0d9e56 100644 --- a/server/src/main/java/org/apache/accumulo/server/master/LiveTServerSet.java +++ b/server/src/main/java/org/apache/accumulo/server/master/LiveTServerSet.java @@ -287,7 +287,7 @@ public class LiveTServerSet implements Watcher { } } else { locklessServers.remove(server); - ServerServices services = new ServerServices(new String(lockData)); + ServerServices services = new ServerServices(new String(lockData, Constants.UTF8)); InetSocketAddress client = services.getAddress(ServerServices.Service.TSERV_CLIENT); InetSocketAddress addr = AddressUtil.parseAddress(server, Property.TSERV_CLIENTPORT); TServerInstance instance = new TServerInstance(client, stat.getEphemeralOwner());