Exemplo n.º 1
0
 public void removeTempTableByName(final String tempTableName, CommandContext context)
     throws TeiidProcessingException {
   TempTableSynchronization synch = getSynchronization(context);
   tempMetadataStore.removeTempGroup(tempTableName);
   final TempTable table = this.tempTables.remove(tempTableName);
   if (table == null) {
     return;
   }
   if (transactionMode != TransactionMode.ISOLATE_WRITES
       || synch == null
       || !synch.existingTables.contains(table.getId())) {
     table.remove();
   }
 }
Exemplo n.º 2
0
    public TempTableSynchronization(final String id) {
      this.id = id;
      for (TempTable tempTable : tempTables.values()) {
        existingTables.add(tempTable.getId());
      }
      if (transactionMode == TransactionMode.ISOLATE_WRITES) {
        addCallback(
            new TransactionCallback() {
              private Map<String, TempMetadataID> clonedMetadata =
                  new ConcurrentHashMap<String, TempMetadataID>(tempMetadataStore.getData());
              private Map<String, TempTable> clonedTables =
                  new ConcurrentHashMap<String, TempTable>(tempTables);

              @Override
              public void rollback() {
                LogManager.logDetail(
                    LogConstants.CTX_DQP,
                    "Rolling back txn",
                    id,
                    "restoring",
                    clonedTables.keySet(),
                    "using rollback tables",
                    tables); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                // remove any tables created in the scope of this txn
                tempTables.values().removeAll(clonedTables.values());
                for (TempTable table : tempTables.values()) {
                  table.remove();
                }

                // restore the state
                tempMetadataStore.getData().clear();
                tempMetadataStore.getData().putAll(clonedMetadata);
                tempTables.clear();
                tempTables.putAll(clonedTables);

                // overlay the rollback tables
                tempTables.putAll(tables);
              }

              @Override
              public void commit() {
                // remove any original tables that were removed in this txn
                clonedTables.values().removeAll(tempTables.values());
                for (TempTable table : clonedTables.values()) {
                  table.remove();
                }
              }
            });
      }
    }
Exemplo n.º 3
0
 private TempTable getTempTable(
     String tempTableID,
     Command command,
     BufferManager buffer,
     boolean delegate,
     boolean forUpdate,
     CommandContext context)
     throws TeiidProcessingException {
   final TempTable tempTable = tempTables.get(tempTableID);
   if (tempTable != null) {
     // isolate if needed
     if (forUpdate) {
       if (transactionMode == TransactionMode.ISOLATE_WRITES) {
         TransactionContext tc = context.getTransactionContext();
         if (tc != null) {
           TempTableSynchronization synch = getSynchronization(context);
           if (synch != null && synch.existingTables.contains(tempTable.getId())) {
             TempTable result = synch.tables.get(tempTableID);
             if (result == null) {
               synchronized (synch) {
                 if (synch.isCompleted()) {
                   throw new AssertionError("Expected active transaction"); // $NON-NLS-1$
                 }
                 if (!tempTable.getActive().compareAndSet(0, 1)) {
                   throw new TeiidProcessingException(
                       QueryPlugin.Event.TEIID30227,
                       QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30227, tempTableID));
                 }
                 synch.tables.put(tempTableID, tempTable.clone());
               }
             }
             return tempTable;
           }
         } else if (tempTable.getActive().get() != 0) {
           throw new TeiidProcessingException(
               QueryPlugin.Event.TEIID30227,
               QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30227, tempTableID));
         }
       }
     } else if (transactionMode == TransactionMode.ISOLATE_READS) {
       TransactionContext tc = context.getTransactionContext();
       if (tc != null && tc.getIsolationLevel() > Connection.TRANSACTION_READ_COMMITTED) {
         TempTableSynchronization synch = getSynchronization(context);
         if (synch != null) {
           TempTable result = synch.tables.get(tempTableID);
           if (result == null) {
             result = tempTable;
             synchronized (synch) {
               if (!synch.isCompleted()) {
                 synch.tables.put(tempTableID, tempTable);
                 result.getActive().getAndIncrement();
               }
             }
           }
           return result;
         }
       }
     }
     return tempTable;
   }
   if (delegate && this.parentTempTableStore != null) {
     return this.parentTempTableStore.getTempTable(
         tempTableID, command, buffer, delegate, forUpdate, context);
   }
   return null;
 }