Exemplo n.º 1
0
TEST_F(TransactionTests, read_own_writes) {

  auto writeCtx = hyrise::tx::TransactionManager::getInstance().buildContext();

  auto& mod = hyrise::tx::TransactionManager::getInstance()[writeCtx.tid];

  ASSERT_EQ(0u, mod.inserted.size());
  size_t before = linxxxs->size();
  // Add One read all
  InsertScan is;
  is.setTXContext(writeCtx);
  is.addInput(linxxxs);
  is.setInputData(one_row);
  is.execute();

  ASSERT_EQ(1u, mod.inserted.size());
  ASSERT_EQ(1u, mod.inserted[linxxxs].size());


  ProjectionScan ps;
  ps.addField(0);
  ps.setTXContext(writeCtx);
  ps.addInput(is.getResultTable());
  ps.execute();

  ValidatePositions vp;
  vp.setTXContext(writeCtx);
  vp.addInput(ps.getResultTable());
  vp.execute();

  auto r1 = vp.getResultTable();
  ASSERT_EQ(before + 1, r1->size());
}
Exemplo n.º 2
0
TEST_F(TransactionTests, concurrent_writer) {

  auto writeCtx = tx::TransactionManager::getInstance().buildContext();
  auto writeCtx2 = tx::TransactionManager::getInstance().buildContext();

  auto& mod = tx::TransactionManager::getInstance()[writeCtx.tid];
  ASSERT_EQ(0u, mod.inserted.size());


  size_t before = linxxxs->size();
  // Add One read all
  InsertScan is;
  is.setTXContext(writeCtx);
  is.addInput(linxxxs);
  is.setInputData(one_row);
  is.execute();


  ASSERT_EQ(1u, mod.inserted.size());
  ASSERT_EQ(1u, mod.inserted[linxxxs].size());

  // Add One read all
  InsertScan is2;
  is2.setTXContext(writeCtx2);
  is2.addInput(linxxxs);
  is2.setInputData(second_row);
  is2.execute();

  ASSERT_EQ(1u, mod.inserted[linxxxs].size());

  ASSERT_EQ(before + 2, linxxxs->size());

  // Commit the changes from the first TX and check that we still dont see it for the second
  Commit c;
  c.addInput(linxxxs);
  c.setTXContext(writeCtx);
  c.execute();

  ProjectionScan ps;
  ps.addInput(linxxxs);
  ps.setTXContext(writeCtx2);
  ps.addField(0);
  ps.addField(1);
  ps.execute();

  ValidatePositions vp;
  vp.setTXContext(writeCtx2);
  vp.addInput(ps.getResultTable());
  vp.execute();

  auto res = vp.getResultTable();

  ASSERT_EQ(before + 1, res->size());
  ASSERT_EQ(222, res->getValue<hyrise_int_t>(1, res->size() - 1));
}
Exemplo n.º 3
0
  virtual void SetUp() {
    AccessTest::SetUp();
    t = io::Loader::shortcuts::load("test/index_test.tbl");

    {
      CreateGroupkeyIndex ci;
      ci.addInput(t);
      ci.addField(0);
      ci.addField(3);
      ci.setIndexName("test_main_idx_0_and_3");
      ci.execute();

      CreateDeltaIndex cd;
      cd.addInput(t);
      cd.addField(0);
      cd.addField(3);
      cd.setIndexName("test_delta_idx_0_and_3");
      cd.execute();
    }

    {
      CreateGroupkeyIndex ci;
      ci.addInput(t);
      ci.addField(0);
      ci.addField(2);
      ci.setIndexName("test_main_idx_0_and_2");
      ci.execute();

      CreateDeltaIndex cd;
      cd.addInput(t);
      cd.addField(0);
      cd.addField(2);
      cd.setIndexName("test_delta_idx_0_and_2");
      cd.execute();
    }

    auto row = io::Loader::shortcuts::load("test/index_insert_test.tbl");
    auto ctx = tx::TransactionManager::getInstance().buildContext();
    InsertScan ins;
    ins.setTXContext(ctx);
    ins.addInput(t);
    ins.setInputData(row);
    ins.execute();

    Commit c;
    c.setTXContext(ctx);
    c.execute();
  }
Exemplo n.º 4
0
void parallel_writer_thread_function(storage::store_ptr_t linxxxs,
                                     storage::atable_ptr_t one_row,
                                     const size_t inserts_per_thread) {

  // do 1K inserts
  for (size_t i = 0; i < inserts_per_thread; ++i) {

    auto writeCtx = tx::TransactionManager::getInstance().buildContext();

    InsertScan is;
    is.setTXContext(writeCtx);
    is.addInput(linxxxs);
    is.setInputData(one_row);
    is.execute();

    // Commit the changes
    tx::TransactionManager::commitAndRespond(writeCtx, true);
  }
}
Exemplo n.º 5
0
TEST_F(SelectTests, select_after_insert_simple) {
  auto ctx = tx::TransactionManager::getInstance().buildContext();
  hyrise::storage::atable_ptr_t s = io::Loader::shortcuts::load("test/lin_xxs.tbl");
  auto initial_size = s->size();
  hyrise::storage::atable_ptr_t data = s->copy_structure_modifiable(nullptr, s->size());
  data->resize(1);
  for (std::size_t i=0; i <= 9; ++i) {
    data->setValue<hyrise_int_t>(i, 0, 1000+i);
  }
  // insert data
  InsertScan isc;
  isc.setTXContext(ctx);
  isc.addInput(s);
  isc.setInputData(data);
  isc.execute();


  ASSERT_EQ(initial_size + 1, isc.getResultTable(0)->size());
}
Exemplo n.º 6
0
TEST_F(TransactionTests, read_your_own_inserted_and_deleted) {

  auto writeCtx = tx::TransactionManager::getInstance().buildContext();

  InsertScan is;
  is.setTXContext(writeCtx);
  is.addInput(linxxxs);
  is.setInputData(one_row);
  is.execute();

  size_t before = linxxxs->size();

  // Add One read all
  auto pc = storage::PointerCalculator::create(linxxxs, new pos_list_t({before - 1}));
  ASSERT_EQ(1u, pc->size());

  DeleteOp del;
  del.setTXContext(writeCtx);
  del.addInput(pc);
  del.execute();

  ProjectionScan ps;
  ps.addInput(linxxxs);
  ps.setTXContext(writeCtx);
  ps.addField(0);
  ps.addField(1);
  ps.execute();

  ValidatePositions vp;
  vp.setTXContext(writeCtx);
  vp.addInput(ps.getResultTable());
  vp.execute();

  auto res = vp.getResultTable();
  ASSERT_EQ(before - 1, res->size()) << "We expect not to see the row we inserted and deleted earlier";
}
Exemplo n.º 7
0
TEST_F(TransactionTests, insert_and_delete_same_row) {

  auto reference = io::Loader::shortcuts::load("test/lin_xxxs.tbl");

  auto writeCtx = tx::TransactionManager::getInstance().buildContext();
  auto& mod = tx::TransactionManager::getInstance()[writeCtx.tid];

  ASSERT_EQ(0u, mod.inserted.size());
  size_t before = linxxxs->size();

  // insert one row
  auto row = io::Loader::shortcuts::load("test/insert_one.tbl");

  InsertScan is;
  is.setTXContext(writeCtx);
  is.addInput(linxxxs);
  is.setInputData(row);
  is.execute();

  ASSERT_EQ(1u, mod.inserted.size());
  ASSERT_EQ(1u, mod.inserted[linxxxs].size());

  ASSERT_EQ(0u, mod.deleted.size());
  ASSERT_EQ(0u, mod.deleted[linxxxs].size());

  size_t after_insert = linxxxs->size();

  // create PC to simulate position
  auto pc2 = storage::PointerCalculator::create(linxxxs, new pos_list_t({before}));

  DeleteOp del;
  del.setTXContext(writeCtx);
  del.addInput(pc2);
  del.execute();

  Commit c;
  c.setTXContext(writeCtx);
  c.execute();

  size_t after_delete = linxxxs->size();

  // load table and validate positions for reference
  auto readCtx = tx::TransactionManager::getInstance().buildContext();

  auto expr = std::unique_ptr<GreaterThanExpression<storage::hyrise_int_t> >(
      new GreaterThanExpression<storage::hyrise_int_t>(0, 1, 0));


  TableScan ts(std::move(expr));
  ts.setTXContext(readCtx);
  ts.addInput(linxxxs);
  ts.execute();

  ValidatePositions vp;
  vp.setTXContext(readCtx);
  vp.addInput(ts.getResultTable());
  vp.execute();

  const auto& result = vp.getResultTable();

  ASSERT_EQ(before + 1, after_insert);
  ASSERT_EQ(before + 1, after_delete);
  ASSERT_EQ(before, result->size());

  // we update and deleted the same row, should be the same as deleting the row
  EXPECT_RELATION_EQ(result, reference);
}