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