@Override
  protected boolean hasAnotherFacet(Ice.Identity ident, String facet) {
    _deactivateController.lock();
    try {
      java.util.Map<String, ObjectStore> storeMapCopy;
      synchronized (this) {
        storeMapCopy = new java.util.HashMap<String, ObjectStore>(_storeMap);
      }

      TransactionI tx = beforeQuery();

      for (java.util.Map.Entry<String, ObjectStore> entry : storeMapCopy.entrySet()) {
        //
        // Do not check this facet again
        //
        if (!facet.equals(entry.getKey())) {
          ObjectStore store = entry.getValue();

          if (tx == null && store.cache().getIfPinned(ident) != null) {
            return true;
          }

          if (store.dbHasObject(ident, tx)) {
            return true;
          }
        }
      }

      return false;
    } finally {
      _deactivateController.unlock();
    }
  }
  @Override
  public boolean hasFacet(Ice.Identity ident, String facet) {
    checkIdentity(ident);
    if (facet == null) {
      facet = "";
    }

    _deactivateController.lock();
    try {
      ObjectStore store = findStore(facet, false);

      if (store == null) {
        return false;
      }

      TransactionI tx = beforeQuery();

      if (tx == null) {
        EvictorElement element = (EvictorElement) store.cache().getIfPinned(ident);
        if (element != null) {
          return true;
        }

        return store.dbHasObject(ident, null);
      } else {
        return store.dbHasObject(ident, tx);
      }
    } finally {
      _deactivateController.unlock();
    }
  }
Beispiel #3
0
  /** Tests partition operations */
  @Test
  public void testPartitionOps()
      throws MetaException, InvalidObjectException, NoSuchObjectException, InvalidInputException {
    Database db1 = new Database(DB1, "description", "locationurl", null);
    objectStore.createDatabase(db1);
    StorageDescriptor sd =
        new StorageDescriptor(
            null,
            "location",
            null,
            null,
            false,
            0,
            new SerDeInfo("SerDeName", "serializationLib", null),
            null,
            null,
            null);
    HashMap<String, String> tableParams = new HashMap<String, String>();
    tableParams.put("EXTERNAL", "false");
    FieldSchema partitionKey1 = new FieldSchema("Country", "String", "");
    FieldSchema partitionKey2 = new FieldSchema("State", "String", "");
    Table tbl1 =
        new Table(
            TABLE1,
            DB1,
            "owner",
            1,
            2,
            3,
            sd,
            Arrays.asList(partitionKey1, partitionKey2),
            tableParams,
            "viewOriginalText",
            "viewExpandedText",
            "MANAGED_TABLE");
    objectStore.createTable(tbl1);
    HashMap<String, String> partitionParams = new HashMap<String, String>();
    partitionParams.put("PARTITION_LEVEL_PRIVILEGE", "true");
    List<String> value1 = Arrays.asList("US", "CA");
    Partition part1 = new Partition(value1, DB1, TABLE1, 111, 111, sd, partitionParams);
    objectStore.addPartition(part1);
    List<String> value2 = Arrays.asList("US", "MA");
    Partition part2 = new Partition(value2, DB1, TABLE1, 222, 222, sd, partitionParams);
    objectStore.addPartition(part2);

    Deadline.startTimer("getPartition");
    List<Partition> partitions = objectStore.getPartitions(DB1, TABLE1, 10);
    Assert.assertEquals(2, partitions.size());
    Assert.assertEquals(111, partitions.get(0).getCreateTime());
    Assert.assertEquals(222, partitions.get(1).getCreateTime());

    objectStore.dropPartition(DB1, TABLE1, value1);
    partitions = objectStore.getPartitions(DB1, TABLE1, 10);
    Assert.assertEquals(1, partitions.size());
    Assert.assertEquals(222, partitions.get(0).getCreateTime());

    objectStore.dropPartition(DB1, TABLE1, value2);
    objectStore.dropTable(DB1, TABLE1);
    objectStore.dropDatabase(DB1);
  }
Beispiel #4
0
 private String createArray(Object[] objArray) {
   String out = "<array type=\"objref\">";
   ObjectStore objStore = ObjectStore.getInstance();
   for (Object o : objArray) {
     String ref = objStore.add(o);
     out += this.createObjRef(ref);
   }
   out += "</array>";
   return out;
 }
 @Override
 public Table markPartitionForEvent(
     String dbName, String tblName, Map<String, String> partVals, PartitionEventType evtType)
     throws MetaException, UnknownTableException, InvalidPartitionException,
         UnknownPartitionException {
   return objectStore.markPartitionForEvent(dbName, tblName, partVals, evtType);
 }
 @Override
 public boolean isPartitionMarkedForEvent(
     String dbName, String tblName, Map<String, String> partName, PartitionEventType evtType)
     throws MetaException, UnknownTableException, InvalidPartitionException,
         UnknownPartitionException {
   return objectStore.isPartitionMarkedForEvent(dbName, tblName, partName, evtType);
 }
 @Override
 public boolean deletePartitionColumnStatistics(
     String dbName, String tableName, String partName, List<String> partVals, String colName)
     throws NoSuchObjectException, MetaException, InvalidObjectException, InvalidInputException {
   return objectStore.deletePartitionColumnStatistics(
       dbName, tableName, partName, partVals, colName);
 }
  /** Test that transactions can be aborted */
  public void testAbortTransactions() throws Exception {
    Address address1 = new Address();
    address1.setAddress("Address 3");
    Address address2 = new Address();
    address2.setAddress("Address 4");

    Query q = new Query();
    QueryClass qcAddress = new QueryClass(Address.class);
    QueryField qf = new QueryField(qcAddress, "address");
    ConstraintSet cs1 = new ConstraintSet(ConstraintOp.OR);
    cs1.addConstraint(new SimpleConstraint(qf, ConstraintOp.MATCHES, new QueryValue("Address%")));
    q.addToSelect(qcAddress);
    q.addFrom(qcAddress);
    q.addToOrderBy(qf);
    q.setConstraint(cs1);

    Results res = writer.execute(q);
    assertEquals(res.toString(), 0, res.size());

    res = realOs.execute(q);
    assertEquals(res.toString(), 0, res.size());

    writer.beginTransaction();
    assertTrue(writer.isInTransaction());

    writer.store(address1);
    writer.store(address2);

    // TODO: These lines now fail, because we do not allow querying on writers with uncommitted
    // data. The writer should relax this restriction.
    res = writer.execute(q);
    assertEquals(2, res.size());

    res = realOs.execute(q);
    assertEquals(res.toString(), 0, res.size());

    writer.abortTransaction();
    assertFalse(writer.isInTransaction());

    // Should be nothing there unless we commit

    res = writer.execute(q);
    assertEquals(res.toString(), 0, res.size());

    res = realOs.execute(q);
    assertEquals(res.toString(), 0, res.size());
  }
 @Override
 public boolean commitTransaction() {
   if (shouldCommitSucceed) {
     return objectStore.commitTransaction();
   } else {
     return false;
   }
 }
Beispiel #10
0
  private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();

    // Serialize local snapshots cache
    if (!isUsingSharedSnapshotCache()) {
      out.writeObject(objectStore.getDataRowCache());
    }
  }
  /** Test that transactions do actually commit and that isInTransaction() works. */
  public void testCommitTransactions() throws Exception {
    Address address1 = new Address();
    address1.setAddress("Address 1");
    Address address2 = new Address();
    address2.setAddress("Address 2");

    Query q = new Query();
    QueryClass qcAddress = new QueryClass(Address.class);
    QueryField qf = new QueryField(qcAddress, "address");
    ConstraintSet cs1 = new ConstraintSet(ConstraintOp.OR);
    cs1.addConstraint(new SimpleConstraint(qf, ConstraintOp.MATCHES, new QueryValue("Address%")));
    q.addToSelect(qcAddress);
    q.addFrom(qcAddress);
    q.addToOrderBy(qf);
    q.setConstraint(cs1);

    try {
      writer.beginTransaction();
      assertTrue(writer.isInTransaction());

      writer.store(address1);
      writer.store(address2);

      // Should be nothing in OS until we commit
      Results res = realOs.execute(q);
      assertEquals(0, res.size());

      // However, they should be in the WRITER.
      // TODO: These lines now fail, because we do not allow querying on writers with uncommitted
      // data. The writer should relax this restriction.
      res = writer.execute(q);
      assertEquals(2, res.size());

      writer.commitTransaction();
      assertFalse(writer.isInTransaction());
      res = realOs.execute(q);
      assertEquals(2, res.size());
      assertEquals(address1, (Address) ((ResultsRow) res.get(0)).get(0));
      assertEquals(address2, (Address) ((ResultsRow) res.get(1)).get(0));

    } finally {
      writer.delete(address1);
      writer.delete(address2);
    }
  }
  synchronized Ice.Object evict(Ice.Identity ident, ObjectStore store) {
    EvictorElement element = (EvictorElement) store.cache().unpin(ident);

    if (element != null) {
      element.evict(false);
      return element.servant;
    }
    return null;
  }
Beispiel #13
0
  /**
   * Creates a new DataContext with parent DataChannel and ObjectStore.
   *
   * @since 1.2
   */
  public DataContext(DataChannel channel, ObjectStore objectStore) {

    // inject self as parent context
    if (objectStore != null) {
      this.objectStore = objectStore;
      objectStore.setContext(this);
    }

    if (channel != null) {
      attachToChannel(channel);
    }

    if (objectStore != null) {
      DataDomain domain = getParentDataDomain();
      this.usingSharedSnaphsotCache =
          domain != null && objectStore.getDataRowCache() == domain.getSharedSnapshotCache();
    }
  }
Beispiel #14
0
  /**
   * If the parent channel is a DataContext, reverts local changes to make this context look like
   * the parent, if the parent channel is a DataDomain, reverts all changes.
   *
   * @since 1.2
   */
  @Override
  public void rollbackChangesLocally() {
    if (objectStore.hasChanges()) {
      GraphDiff diff = getObjectStore().getChanges();

      getObjectStore().objectsRolledBack();
      fireDataChannelRolledback(this, diff);
    }
  }
 @Override
 public List<HiveObjectPrivilege> listPrincipalTableColumnGrants(
     String principalName,
     PrincipalType principalType,
     String dbName,
     String tableName,
     String columnName) {
   return objectStore.listPrincipalTableColumnGrants(
       principalName, principalType, dbName, tableName, columnName);
 }
 @Override
 public List<MPartitionPrivilege> listPrincipalPartitionGrants(
     String principalName,
     PrincipalType principalType,
     String dbName,
     String tableName,
     String partName) {
   return objectStore.listPrincipalPartitionGrants(
       principalName, principalType, dbName, tableName, partName);
 }
 @Override
 public Partition getPartitionWithAuth(
     String dbName,
     String tblName,
     List<String> partVals,
     String userName,
     List<String> groupNames)
     throws MetaException, NoSuchObjectException, InvalidObjectException {
   return objectStore.getPartitionWithAuth(dbName, tblName, partVals, userName, groupNames);
 }
Beispiel #18
0
  /** Run a dummy request on the current transaction to extends its validity. */
  public void ping() {
    final Store randomStore = stores.iterator().next();
    final ObjectStore pingObjectStore = getObjectStore(randomStore);

    pingObjectStore
        .get(0)
        .addCallback(
            new AsyncCallback<Request>() {

              @Override
              public void onFailure(Throwable caught) {
                Log.trace("IndexedDB PING failed", caught);
              }

              @Override
              public void onSuccess(Request result) {
                Log.trace("IndexedDB PING successful");
              }
            });
  }
Beispiel #19
0
  /** Test database operations */
  @Test
  public void testDatabaseOps()
      throws MetaException, InvalidObjectException, NoSuchObjectException {
    Database db1 = new Database(DB1, "description", "locationurl", null);
    Database db2 = new Database(DB2, "description", "locationurl", null);
    objectStore.createDatabase(db1);
    objectStore.createDatabase(db2);

    List<String> databases = objectStore.getAllDatabases();
    Assert.assertEquals(2, databases.size());
    Assert.assertEquals(DB1, databases.get(0));
    Assert.assertEquals(DB2, databases.get(1));

    objectStore.dropDatabase(DB1);
    databases = objectStore.getAllDatabases();
    Assert.assertEquals(1, databases.size());
    Assert.assertEquals(DB2, databases.get(0));

    objectStore.dropDatabase(DB2);
  }
Beispiel #20
0
  @Before
  public void setUp() throws Exception {
    HiveConf conf = new HiveConf();
    conf.setVar(
        HiveConf.ConfVars.METASTORE_EXPRESSION_PROXY_CLASS,
        MockPartitionExpressionProxy.class.getName());

    objectStore = new ObjectStore();
    objectStore.setConf(conf);
    dropAllStoreObjects(objectStore);
  }
 @Override
 public boolean grantRole(
     Role role,
     String userName,
     PrincipalType principalType,
     String grantor,
     PrincipalType grantorType,
     boolean grantOption)
     throws MetaException, NoSuchObjectException, InvalidObjectException {
   return objectStore.grantRole(role, userName, principalType, grantor, grantorType, grantOption);
 }
 @Override
 public boolean getPartitionsByExpr(
     String dbName,
     String tblName,
     byte[] expr,
     String defaultPartitionName,
     short maxParts,
     List<Partition> result)
     throws TException {
   return objectStore.getPartitionsByExpr(
       dbName, tblName, expr, defaultPartitionName, maxParts, result);
 }
 @Override
 public PrincipalPrivilegeSet getColumnPrivilegeSet(
     String dbName,
     String tableName,
     String partitionName,
     String columnName,
     String userName,
     List<String> groupNames)
     throws InvalidObjectException, MetaException {
   return objectStore.getColumnPrivilegeSet(
       dbName, tableName, partitionName, columnName, userName, groupNames);
 }
 @Override
 public List<Partition> listPartitionsPsWithAuth(
     String dbName,
     String tblName,
     List<String> partVals,
     short maxParts,
     String userName,
     List<String> groupNames)
     throws MetaException, InvalidObjectException, NoSuchObjectException {
   return objectStore.listPartitionsPsWithAuth(
       dbName, tblName, partVals, maxParts, userName, groupNames);
 }
 @Override
 public List<HiveObjectPrivilege> listPrincipalPartitionColumnGrants(
     String principalName,
     PrincipalType principalType,
     String dbName,
     String tableName,
     List<String> partVals,
     String partName,
     String columnName) {
   return objectStore.listPrincipalPartitionColumnGrants(
       principalName, principalType, dbName, tableName, partVals, partName, columnName);
 }
  private Ice.Object loadCachedServant(Ice.Identity ident, ObjectStore store) {
    for (; ; ) {
      EvictorElement element = (EvictorElement) store.cache().pin(ident);

      if (element == null) {
        return null;
      }

      synchronized (this) {
        if (element.stale) {
          //
          // try again
          //
          continue;
        }

        element.fixEvictPosition();

        //
        // if _evictorSize is 0, I may evict myself ... no big deal
        //
        evict();

        if (_trace >= 3) {
          _communicator
              .getLogger()
              .trace(
                  "Freeze.Evictor",
                  "loaded \""
                      + _communicator.identityToString(ident)
                      + "\" with facet \""
                      + store.facet()
                      + "\" into the cache");
        }
        return element.servant;
      }
    }
  }
Beispiel #27
0
  // serialization support
  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {

    // TODO: most of this should be in the superclass, especially the code
    // connecting
    // super transient ivars

    // read non-transient properties
    in.defaultReadObject();

    // deserialize local snapshots cache
    if (!isUsingSharedSnapshotCache()) {
      DataRowStore cache = (DataRowStore) in.readObject();
      objectStore.setDataRowCache(cache);
    }

    // CayenneDataObjects have a transient DataContext
    // because at deserialize time the datacontext may need to be different
    // than the one at serialize time (for programmer defined reasons).
    // So, when a DataObject is resurrected because it's DataContext was
    // serialized, it will then set the objects DataContext to the correct
    // one
    // If deserialized "otherwise", it will not have a DataContext.

    synchronized (getObjectStore()) {
      Iterator<?> it = objectStore.getObjectIterator();
      while (it.hasNext()) {
        Persistent object = (Persistent) it.next();
        object.setObjectContext(this);
      }
    }

    // ... deferring initialization of transient properties of this context
    // till first
    // access, so that it can attach to Cayenne runtime using appropriate
    // thread
    // injector.
  }
Beispiel #28
0
  void associate(
      ObjectStore store, com.sleepycat.db.Transaction txn, boolean createDb, boolean populateIndex)
      throws com.sleepycat.db.DatabaseException, java.io.FileNotFoundException {
    assert (txn != null);
    _store = store;

    _dbName = EvictorI.indexPrefix + store.dbName() + "." + _name;

    com.sleepycat.db.SecondaryConfig config = new com.sleepycat.db.SecondaryConfig();
    config.setAllowCreate(createDb);
    config.setAllowPopulate(populateIndex);
    config.setSortedDuplicates(true);
    config.setType(com.sleepycat.db.DatabaseType.BTREE);
    config.setKeyCreator(this);

    Ice.Properties properties = store.evictor().communicator().getProperties();
    String propPrefix = "Freeze.Evictor." + store.evictor().filename() + ".";

    int btreeMinKey = properties.getPropertyAsInt(propPrefix + _dbName + ".BtreeMinKey");
    if (btreeMinKey > 2) {
      if (store.evictor().trace() >= 1) {
        store
            .evictor()
            .communicator()
            .getLogger()
            .trace(
                "Freeze.Evictor",
                "Setting \""
                    + store.evictor().filename()
                    + "."
                    + _dbName
                    + "\"'s btree minkey to "
                    + btreeMinKey);
      }
      config.setBtreeMinKey(btreeMinKey);
    }

    boolean checksum = properties.getPropertyAsInt(propPrefix + "Checksum") > 0;
    if (checksum) {
      //
      // No tracing
      //
      config.setChecksum(true);
    }

    //
    // Can't change page size
    //

    _db =
        _store
            .evictor()
            .dbEnv()
            .getEnv()
            .openSecondaryDatabase(txn, _store.evictor().filename(), _dbName, _store.db(), config);
  }
  public void testWriteBatchingAndGetObject() throws Exception {
    Address address1 = new Address();
    address1.setAddress("Address 1");

    writer.flushObjectById();
    realOs.flushObjectById();

    try {
      writer.beginTransaction();
      writer.store(address1);
      assertNotNull(writer.getObjectById(address1.getId(), Address.class));
    } finally {
      if (writer.isInTransaction()) {
        writer.abortTransaction();
      }
    }
  }
    ServantHolder(Ice.Current current, ObjectStore store) {
      _current = current;
      _store = store;

      ServantHolder sh = findServantHolder(_current.id, _store);
      if (sh != null) {
        if (!sh._removed) {
          _rec = sh._rec;
          _readOnly = sh._readOnly;

          if (_trace >= 3) {
            _communicator
                .getLogger()
                .trace(
                    "Freeze.Evictor",
                    "found \""
                        + _communicator.identityToString(_current.id)
                        + "\" with facet \""
                        + _store.facet()
                        + "\" in current context");
          }
        }
      } else {
        //
        // Let's load this servant
        //
        _rec = store.load(current.id, _tx);
        if (_rec != null) {
          if (_trace >= 3) {
            _communicator
                .getLogger()
                .trace(
                    "Freeze.Evictor",
                    "loaded \""
                        + _communicator.identityToString(_current.id)
                        + "\" with facet \""
                        + _store.facet()
                        + "\" into current context");
          }

          _stack.push(this);
          _ownServant = true;
        }
      }
    }