23
23
import java .io .IOException ;
24
24
import java .math .BigInteger ;
25
25
import java .util .Base64 ;
26
- import java .util .HashMap ;
27
- import java .util .Map ;
28
26
import java .util .SortedMap ;
29
27
import java .util .SortedSet ;
30
28
import java .util .TreeMap ;
34
32
import java .util .function .Function ;
35
33
36
34
import org .apache .accumulo .core .Constants ;
37
- import org .apache .accumulo .core .client .NamespaceNotFoundException ;
38
35
import org .apache .accumulo .core .client .admin .TabletMergeability ;
39
36
import org .apache .accumulo .core .clientImpl .AcceptableThriftTableOperationException ;
40
- import org .apache .accumulo .core .clientImpl .Namespace ;
41
- import org .apache .accumulo .core .clientImpl .Namespaces ;
42
37
import org .apache .accumulo .core .clientImpl .TabletMergeabilityUtil ;
43
38
import org .apache .accumulo .core .clientImpl .thrift .TableOperation ;
44
39
import org .apache .accumulo .core .clientImpl .thrift .TableOperationExceptionType ;
64
59
import org .slf4j .Logger ;
65
60
import org .slf4j .LoggerFactory ;
66
61
67
- import com .google .common .base .Preconditions ;
68
-
69
62
public class Utils {
70
63
private static final byte [] ZERO_BYTE = {'0' };
71
64
private static final Logger log = LoggerFactory .getLogger (Utils .class );
@@ -74,10 +67,11 @@ public class Utils {
74
67
* Checks that a table name is only used by the specified table id or not used at all.
75
68
*/
76
69
public static void checkTableNameDoesNotExist (ServerContext context , String tableName ,
77
- TableId tableId , TableOperation operation ) throws AcceptableThriftTableOperationException {
70
+ NamespaceId destNamespaceId , TableId tableId , TableOperation operation )
71
+ throws AcceptableThriftTableOperationException {
72
+
73
+ var newTableName = TableNameUtil .qualify (tableName ).getSecond ();
78
74
79
- final Map <NamespaceId ,String > namespaces = new HashMap <>();
80
- final boolean namespaceInTableName = tableName .contains ("." );
81
75
try {
82
76
for (String tid : context .getZooSession ().asReader ()
83
77
.getChildren (context .getZooKeeperRoot () + Constants .ZTABLES )) {
@@ -86,36 +80,17 @@ public static void checkTableNameDoesNotExist(ServerContext context, String tabl
86
80
try {
87
81
final byte [] tname =
88
82
context .getZooSession ().asReader ().getData (zTablePath + Constants .ZTABLE_NAME );
89
- Preconditions .checkState (tname != null , "Malformed table entry in ZooKeeper at %s" ,
90
- zTablePath );
91
83
92
- String namespaceName = Namespace . DEFAULT . name ();
93
- if ( namespaceInTableName ) {
84
+ if ( newTableName . equals ( new String ( tname , UTF_8 ))) {
85
+ // only make RPCs to get the namespace when the table names are equal
94
86
final byte [] nId =
95
87
context .getZooSession ().asReader ().getData (zTablePath + Constants .ZTABLE_NAMESPACE );
96
- if (nId != null ) {
97
- final NamespaceId namespaceId = NamespaceId .of (new String (nId , UTF_8 ));
98
- if (!namespaceId .equals (Namespace .DEFAULT .id ())) {
99
- namespaceName = namespaces .get (namespaceId );
100
- if (namespaceName == null ) {
101
- try {
102
- namespaceName = Namespaces .getNamespaceName (context , namespaceId );
103
- namespaces .put (namespaceId , namespaceName );
104
- } catch (NamespaceNotFoundException e ) {
105
- throw new AcceptableThriftTableOperationException (null , tableName ,
106
- TableOperation .CREATE , TableOperationExceptionType .OTHER ,
107
- "Table (" + tableId .canonical () + ") contains reference to namespace ("
108
- + namespaceId + ") that doesn't exist" );
109
- }
110
- }
111
- }
88
+ if (destNamespaceId .canonical ().equals (new String (nId , UTF_8 ))
89
+ && !tableId .canonical ().equals (tid )) {
90
+ throw new AcceptableThriftTableOperationException (tid , tableName , operation ,
91
+ TableOperationExceptionType .EXISTS , null );
112
92
}
113
- }
114
93
115
- if (tableName .equals (TableNameUtil .qualified (new String (tname , UTF_8 ), namespaceName ))
116
- && !tableId .equals (TableId .of (tid ))) {
117
- throw new AcceptableThriftTableOperationException (tid , tableName , operation ,
118
- TableOperationExceptionType .EXISTS , null );
119
94
}
120
95
} catch (NoNodeException nne ) {
121
96
log .trace ("skipping tableId {}, either being created or has been deleted." , tid , nne );
0 commit comments