HADOOP-12436. GlobPattern regex library has performance issues with wildcard characters (Matthew Paduano via aw)

This commit is contained in:
Allen Wittenauer 2015-10-22 08:19:56 -07:00
parent 2798723a54
commit 4c0bae240b
11 changed files with 64 additions and 11 deletions

View File

@ -320,6 +320,41 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
For com.google.re2j.* classes:
---------------------------------------------------------------------
This is a work derived from Russ Cox's RE2 in Go, whose license
http://golang.org/LICENSE is as follows:
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its contributors
may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
For hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/fuse-dfs/util/tree.h For hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/fuse-dfs/util/tree.h
--------------------------------------------------------------------- ---------------------------------------------------------------------
Copyright 2002 Niels Provos <provos@citi.umich.edu> Copyright 2002 Niels Provos <provos@citi.umich.edu>

View File

@ -243,6 +243,9 @@ Trunk (Unreleased)
HADOOP-12249. pull argument parsing into a function (aw) HADOOP-12249. pull argument parsing into a function (aw)
HADOOP-12436. GlobPattern regex library has performance issues with
wildcard characters (Matthew Paduano via aw)
BUG FIXES BUG FIXES
HADOOP-11473. test-patch says "-1 overall" even when all checks are +1 HADOOP-11473. test-patch says "-1 overall" even when all checks are +1

View File

@ -191,6 +191,12 @@
<artifactId>ant</artifactId> <artifactId>ant</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.re2j</groupId>
<artifactId>re2j</artifactId>
<version>${re2j.version}</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId> <artifactId>protobuf-java</artifactId>

View File

@ -18,7 +18,7 @@
package org.apache.hadoop.fs; package org.apache.hadoop.fs;
import java.util.regex.PatternSyntaxException; import com.google.re2j.PatternSyntaxException;
import java.io.IOException; import java.io.IOException;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;

View File

@ -18,8 +18,8 @@
package org.apache.hadoop.fs; package org.apache.hadoop.fs;
import java.util.regex.Pattern; import com.google.re2j.Pattern;
import java.util.regex.PatternSyntaxException; import com.google.re2j.PatternSyntaxException;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
@ -164,6 +164,7 @@ public boolean hasWildcard() {
} }
private static void error(String message, String pattern, int pos) { private static void error(String message, String pattern, int pos) {
throw new PatternSyntaxException(message, pattern, pos); String fullMessage = String.format("%s at pos %d", message, pos);
throw new PatternSyntaxException(fullMessage, pattern);
} }
} }

View File

@ -19,8 +19,6 @@
package org.apache.hadoop.metrics2.filter; package org.apache.hadoop.metrics2.filter;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.apache.commons.configuration.SubsetConfiguration; import org.apache.commons.configuration.SubsetConfiguration;
@ -30,6 +28,8 @@
import org.apache.hadoop.metrics2.MetricsFilter; import org.apache.hadoop.metrics2.MetricsFilter;
import org.apache.hadoop.metrics2.MetricsTag; import org.apache.hadoop.metrics2.MetricsTag;
import com.google.re2j.Matcher;
import com.google.re2j.Pattern;
/** /**
* Base class for pattern based filters * Base class for pattern based filters
*/ */

View File

@ -18,12 +18,12 @@
package org.apache.hadoop.metrics2.filter; package org.apache.hadoop.metrics2.filter;
import java.util.regex.Pattern;
import org.apache.hadoop.fs.GlobPattern; import org.apache.hadoop.fs.GlobPattern;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
import com.google.re2j.Pattern;
/** /**
* A glob pattern filter for metrics. * A glob pattern filter for metrics.
* *

View File

@ -18,11 +18,11 @@
package org.apache.hadoop.metrics2.filter; package org.apache.hadoop.metrics2.filter;
import java.util.regex.Pattern;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
import com.google.re2j.Pattern;
/** /**
* A regex pattern filter for metrics * A regex pattern filter for metrics
*/ */

View File

@ -33,7 +33,6 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern;
import javax.security.auth.callback.Callback; import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.CallbackHandler;
@ -75,6 +74,7 @@
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import com.google.re2j.Pattern;
/** /**
* A utility class that encapsulates SASL logic for RPC client * A utility class that encapsulates SASL logic for RPC client
*/ */

View File

@ -18,10 +18,10 @@
package org.apache.hadoop.fs; package org.apache.hadoop.fs;
import java.util.regex.PatternSyntaxException;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import com.google.re2j.PatternSyntaxException;
/** /**
* Tests for glob patterns * Tests for glob patterns
*/ */
@ -69,6 +69,11 @@ private void shouldThrow(String... globs) {
} }
@Test public void testInvalidPatterns() { @Test public void testInvalidPatterns() {
shouldThrow("[", "[[]]", "[][]", "{", "\\"); shouldThrow("[", "[[]]", "{", "\\");
}
@Test(timeout=1000) public void testPathologicalPatterns() {
String badFilename = "job_1429571161900_4222-1430338332599-tda%2D%2D+******************************+++...%270%27%28Stage-1430338580443-39-2000-SUCCEEDED-production%2Dhigh-1430338340360.jhist";
assertMatch(true, badFilename, badFilename);
} }
} }

View File

@ -68,6 +68,9 @@
<jackson.version>1.9.13</jackson.version> <jackson.version>1.9.13</jackson.version>
<jackson2.version>2.2.3</jackson2.version> <jackson2.version>2.2.3</jackson2.version>
<!-- com.google.re2j version -->
<re2j.version>1.0</re2j.version>
<!-- ProtocolBuffer version, used to verify the protoc version and --> <!-- ProtocolBuffer version, used to verify the protoc version and -->
<!-- define the protobuf JAR version --> <!-- define the protobuf JAR version -->
<protobuf.version>2.5.0</protobuf.version> <protobuf.version>2.5.0</protobuf.version>