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