void CatalogDatabaseCache::update(const serialization::CatalogDatabase &proto) {
  DCHECK(ProtoIsValid(proto))
      << "Attempted to create CatalogDatabaseCache from an invalid proto description:\n"
      << proto.DebugString();

  vector<int> new_relation_schema_proto_indices;
  {
    SpinSharedMutexSharedLock<false> read_lock(relations_mutex_);
    for (int i = 0; i < proto.relations_size(); ++i) {
      const auto it = rel_map_.find(proto.relations(i).relation_id());
      if (it == rel_map_.end()) {
        new_relation_schema_proto_indices.push_back(i);
      } else {
        // TODO(quickstep-team): Support schema changes by adding the index of
        // changed schema proto in 'changed_relation_schema_proto_indices'.
      }
    }
  }

  SpinSharedMutexExclusiveLock<false> write_lock(relations_mutex_);
  for (const int i : new_relation_schema_proto_indices) {
    const serialization::CatalogRelationSchema &proto_relation = proto.relations(i);
    auto relation_schema = make_unique<const CatalogRelationSchema>(proto_relation);
    rel_map_.emplace(proto_relation.relation_id(), move(relation_schema));
  }

  // TODO(quickstep-team): Reset the schema for the changes in the following
  // steps for each index in 'changed_relation_schema_proto_indices':
  // 1. Drop the blocks belonged to 'proto.relations(i).relation_id()' in the
  //    buffer pool.
  // 2. Reset the changed schema, while the scheduler ensures no queries will
  //    load back the related blocks.
  // 3. Signal the scheduler to accept new queries for the changed schema.
}
bool CatalogDatabaseCache::ProtoIsValid(const serialization::CatalogDatabase &proto) {
  for (int i = 0; i < proto.relations_size(); ++i) {
    if (!CatalogRelationSchema::ProtoIsValid(proto.relations(i))) {
      return false;
    }
  }

  return true;
}
CatalogDatabaseCache::CatalogDatabaseCache(const serialization::CatalogDatabase &proto) {
  DCHECK(ProtoIsValid(proto))
      << "Attempted to create CatalogDatabaseCache from an invalid proto description:\n"
      << proto.DebugString();

  for (int i = 0; i < proto.relations_size(); ++i) {
    auto relation_schema = make_unique<const CatalogRelationSchema>(proto.relations(i));
    rel_map_.emplace(relation_schema->getID(), move(relation_schema));
  }
}
Ejemplo n.º 4
0
bool CatalogDatabase::ProtoIsValid(const serialization::CatalogDatabase &proto) {
  // Check that proto is fully initialized.
  if (!proto.IsInitialized()) {
    return false;
  }

  for (int i = 0; i < proto.relations_size(); ++i) {
    if (!CatalogRelation::ProtoIsValid(proto.relations(i))) {
      return false;
    }
  }

  return true;
}
Ejemplo n.º 5
0
CatalogDatabase::CatalogDatabase(const serialization::CatalogDatabase &proto) : name_(proto.name()) {
  DCHECK(ProtoIsValid(proto))
      << "Attempted to create CatalogDatabase from an invalid proto description:\n"
      << proto.DebugString();

  for (int index_relations = 0, index_null_relations = 0;
       index_relations < proto.null_relations_size() + proto.relations_size();
       ++index_relations) {
    if (index_null_relations < proto.null_relations_size() &&
        index_relations == proto.null_relations(index_null_relations)) {
      rel_vec_.push_back(NULL);
      ++index_null_relations;
    } else {
      addRelation(new CatalogRelation(proto.relations(index_relations - index_null_relations)));
    }
  }
}