예제 #1
0
void testStore(void) {

  // setup
  struct Command* createDatabaseCommand = createCreateDatabaseCommand("test_store");
  createDatabase(createDatabaseCommand);

  char names[FIELD_SIZE][NAME_LIMIT] = { "name1", "name2", "name3", "name4", };

  char values[FIELD_SIZE][VALUE_LIMIT] = { "1", "value2", "1/1/2015", "3", };

  FieldType types[FIELD_SIZE][1] = { INTEGER, TEXT, DATE, INTEGER, };

  struct Field* fields = createFieldList(names, values, types, 4);
  struct Command* createTableCmd = createCreateTableCommand("table",
      fields);
  createTable(createTableCmd);


  // test
  struct Command* insertCmd = createInsertCommand("table", fields);
  insertTuple(insertCmd);
  values[0][0] = '2';
  insertTuple(insertCmd);

  // teardown
  destroyCommand(createDatabaseCommand);
  destroyCommand(createTableCmd);
}
예제 #2
0
extern "C" void* NdbThreadFuncInsert(void* pArg)
{
    myRandom48Init((long int)NdbTick_CurrentMillisecond());
    unsigned nSucc = 0;
    unsigned nFail = 0;
    Ndb* pNdb = NULL ;
    pNdb = new Ndb("TEST_DB");
    VerifyMethodInt(pNdb, init());
    VerifyMethodInt(pNdb, waitUntilReady());

    while(NdbMutex_Trylock(g_pNdbMutex)) {
        Uint32 nWarehouse = myRandom48(g_nWarehouseCount);
        NdbConnection* pNdbConnection = NULL ;
        VerifyMethodPtr(pNdbConnection, pNdb, startTransaction());
        CHK_TR(pNdbConnection);
        NdbOperation* pNdbOperationW = NULL ;
        VerifyMethodPtr(pNdbOperationW, pNdbConnection, getNdbOperation(c_szWarehouse));
        VerifyMethodInt(pNdbOperationW, insertTuple());
        VerifyMethodInt(pNdbOperationW, equal(c_szWarehouseNumber, nWarehouse));
        VerifyMethodInt(pNdbOperationW, setValue(c_szWarehouseCount, Uint32(1)));
        Uint32 nWarehouseSum = 0;
        for(Uint32 nDistrict=0; nDistrict<g_nDistrictPerWarehouse; ++nDistrict) {
            NdbOperation* pNdbOperationD = NULL ;
            VerifyMethodPtr(pNdbOperationD, pNdbConnection, getNdbOperation(c_szDistrict));
            VerifyMethodInt(pNdbOperationD, insertTuple());
            VerifyMethodInt(pNdbOperationD, equal(c_szDistrictWarehouseNumber, nWarehouse));
            VerifyMethodInt(pNdbOperationD, equal(c_szDistrictNumber, nDistrict));
            VerifyMethodInt(pNdbOperationD, setValue(c_szDistrictCount, Uint32(1)));
            Uint32 nDistrictSum = myRandom48(100);
            nWarehouseSum += nDistrictSum;
            VerifyMethodInt(pNdbOperationD, setValue(c_szDistrictSum, nDistrictSum));
        }
        VerifyMethodInt(pNdbOperationW, setValue(c_szWarehouseSum, nWarehouseSum));
        int iExec = pNdbConnection->execute(Commit);
        int iError = pNdbConnection->getNdbError().code;

        if(iExec<0 && iError!=0 && iError!=266 && iError!=630) {
            ReportMethodInt(iExec, pNdbConnection, "pNdbConnection", "execute(Commit)", __FILE__, __LINE__);
        }
        if(iExec==0) {
            ++nSucc;
        } else {
            ++nFail;
        }
        VerifyMethodVoid(pNdb, closeTransaction(pNdbConnection));
    }
    ndbout << "insert: " << nSucc << " succeeded, " << nFail << " failed " << endl;
    NdbMutex_Unlock(g_pNdbMutex);
    delete pNdb;
    pNdb = NULL ;
    return NULL;
}
예제 #3
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManagerImpl *dbMgr = (DatabaseManagerImpl*) conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
    int ret =0, rc =0;
    if (createTable(dbMgr, "t1") != 0 ) { ret = 3; }
#ifdef WITHINDEX
    if (createIndex(dbMgr, "t1","f1", "idx1") != 0 ) { ret = 4; }
#endif
    rv = conn.startTransaction();
    if (rv != OK) ret = 5; 
    rc = insertTuple(dbMgr, conn, "t1", 10);
    if (rc != 10) ret = 6;
    conn.commit(); 

    rv = conn.startTransaction();
    if (rv != OK) ret = 5; 
    rc = selectTuple(dbMgr, conn, "t1", 10);
    if (rc != 10) ret = 6;
    printf("Before commit\n");
    dbMgr->printDebugLockInfo();
    conn.commit(); 
    printf("After commit\n");
    dbMgr->printDebugLockInfo();
    dropTable(dbMgr, "t1");
    conn.close();
    return ret;
}
예제 #4
0
파일: bLSM.cpp 프로젝트: Bathtor/bLSM
bool bLSM::testAndSetTuple(dataTuple *tuple, dataTuple *tuple2)
{
    bool succ = false;
    static pthread_mutex_t test_and_set_mut = PTHREAD_MUTEX_INITIALIZER;
    pthread_mutex_lock(&test_and_set_mut);

    dataTuple * exists = findTuple_first(-1, tuple2 ? tuple2->strippedkey() : tuple->strippedkey(), tuple2 ? tuple2->strippedkeylen() : tuple->strippedkeylen());

    if(!tuple2 || tuple2->isDelete()) {
      if(!exists || exists->isDelete()) {
        succ = true;
      } else {
        succ = false;
      }
    } else {
      if(tuple2->datalen() == exists->datalen() && !memcmp(tuple2->data(), exists->data(), tuple2->datalen())) {
        succ = true;
      } else {
        succ = false;
      }
    }
    if(exists) dataTuple::freetuple(exists);
    if(succ) insertTuple(tuple);

    pthread_mutex_unlock(&test_and_set_mut);
    return succ;
}
예제 #5
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}

    if ( createTable(dbMgr) != 0 ) { conn.close(); return 3; }
    int inscount =  insertTuple(dbMgr, conn);
    //check the inscount and return error

    Table *table = dbMgr->openTable("t1");
    if (table == NULL)
    {
        printf("Unable to open table\n");
        return 0;
    }


    Condition p1,p2,p3,p4,p5;
    int val1 = 2, val2 = 3, val3 = 4;
    p1.setTerm("f1", OpEquals, &val3);
    p2.setTerm("f2", OpGreaterThan, &val2);
    p3.setTerm("f2", OpEquals, &val3);
    p4.setTerm("f1", OpLessThan, &val1);
    p5.setTerm("f1", OpGreaterThan, &val1);


    Condition cond1, cond1a;
    cond1.setTerm(p1.getPredicate(), OpAnd, p2.getPredicate());
    cond1a.setTerm(cond1.getPredicate(), OpOr, p4.getPredicate());
    table->setCondition(&cond1a);
    printf("Predicate: (f1 ==4 AND f2 >3) OR (f1< 2) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    Condition cond2, cond2a;
    cond2.setTerm(p4.getPredicate(), OpAnd, p2.getPredicate());
    cond2a.setTerm(cond1.getPredicate(), OpOr, cond2.getPredicate());
    table->setCondition(&cond2a);
    printf("Predicate: (f1 ==4 AND f2 >3) OR (f1< 2 AND f2 > 4) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    return 0;

}
예제 #6
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
    int ret =0;
    ret = insertTuple(dbMgr, conn, "t1", 1000);
    conn.close();
    return ret;
}
예제 #7
0
const NdbOperation * KeyOperation::prepare(NdbTransaction *tx) {
  switch(opcode) {
    case 1:  // OP_READ:
      return readTuple(tx);
    case 2:  // OP_INSERT:
      return insertTuple(tx);
    case 4:  // OP_UPDATE:
      return updateTuple(tx);
    case 8:  // OP_WRITE:
      return writeTuple(tx);
    case 16: // OP_DELETE:
      return deleteTuple(tx);
    default:
      return NULL;
  }
}
예제 #8
0
파일: bLSM.cpp 프로젝트: Bathtor/bLSM
void bLSM::replayLog() {
  lsn_t start = tbl_header.log_trunc;
  LogHandle * lh = start ? getLSNHandle(log_file, start) : getLogHandle(log_file);
  const LogEntry * e;
  while((e = nextInLog(lh))) {
    switch(e->type) {
    case UPDATELOG: {
      dataTuple * tup = dataTuple::from_bytes((byte*)stasis_log_entry_update_args_cptr(e));
      insertTuple(tup);
      dataTuple::freetuple(tup);
    } break;
    case INTERNALLOG: { } break;
    default: assert(e->type == UPDATELOG); abort();
    }
  }
  freeLogHandle(lh);
  recovering = false;
  printf("\nLog replay complete.\n");

}
예제 #9
0
void TupleTrackerManager::insertTupleAccesses(boost::unordered_map<std::string, RowOffsets*> *map, int64_t txnId){

	RowOffsets *offsets = NULL;
	std::string tableName;

	//tablename -> set of tuple ids
	boost::unordered_map<std::string, RowOffsets*>::const_iterator iter = map->begin();

	while (iter != map->end()) {
		tableName = iter->first;
		offsets = iter->second;
        boost::unordered_set<uint32_t>::iterator tupleIdIter = offsets->begin();
		while (tupleIdIter != offsets->end()) {
			insertTuple(txnId, tableName, *tupleIdIter);
			tupleIdIter++;
		}

		iter++;
     }

}
예제 #10
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}

    if ( createTable(dbMgr) != 0 ) { conn.close(); return 3; }
#ifdef WITHF1INDEX
    if (createIndex(dbMgr, "f1", "idx1") != 0) {dbMgr->dropTable("t1");
                                        conn.close();
                                        return 4;
                                       }
#endif
#ifdef WITHF1TREEINDEX
    if (createIndex(dbMgr, "f1", "idx1", true) != 0) {dbMgr->dropTable("t1");
                                        conn.close();
                                        return 4;
                                       }
#endif

#ifdef WITHF2INDEX
    if (createIndex(dbMgr, "f2", "idx2") != 0) {dbMgr->dropTable("t1");
                                        conn.close();
                                        return 4;
                                       }
#endif
#ifdef WITHF2TREEINDEX
    if (createIndex(dbMgr, "f2", "idx2", true) != 0) {dbMgr->dropTable("t1");
                                        conn.close();
                                        return 4;
                                       }
#endif

    int inscount =  insertTuple(dbMgr, conn);
    //check the inscount and return error

    Table *table = dbMgr->openTable("t1");
    if (table == NULL)
    {
        printf("Unable to open table\n");
        return 0;
    }


    Condition p1,p2,p3,p4,p5;
    int val1 = 2, val2 = 3, val3 = 4;
    p1.setTerm("f1", OpEquals, &val3);
    p2.setTerm("f2", OpGreaterThan, &val2);
    p3.setTerm("f2", OpEquals, &val3);
    p4.setTerm("f1", OpLessThan, &val3);
    p5.setTerm("f1", OpGreaterThan, &val1);


    Condition cond1, cond1a;
    cond1.setTerm(p1.getPredicate(), OpAnd, p2.getPredicate());
    cond1a.setTerm(cond1.getPredicate(), OpNot);
    table->setCondition(&cond1a);
    printf("Predicate: NOT(f1 ==4 AND f2 >3) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    Condition cond2, cond2a;
    cond2.setTerm(p1.getPredicate(), OpAnd, p3.getPredicate());
    cond2a.setTerm(cond2.getPredicate(), OpNot);
    table->setCondition(&cond2a);
    printf("Predicate: NOT( f1 ==4 AND f2 ==4) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    Condition cond3, cond3a;
    cond3.setTerm(p4.getPredicate(), OpAnd, p5.getPredicate());
    cond3a.setTerm(cond3.getPredicate(), OpNot);
    table->setCondition(&cond3a);
    printf("Predicate: NOT( f1 <4 AND f1 >2) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();


    Condition cond4, cond4a;
    cond4.setTerm(p4.getPredicate(), OpAnd, p2.getPredicate());
    cond4a.setTerm(cond4.getPredicate(), OpNot);
    table->setCondition(&cond4a);
    printf("Predicate: NOT( f1 <4 AND f2 >3) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    Condition cond5, cond5a;
    cond5.setTerm(p2.getPredicate(), OpNot);
    cond5a.setTerm(p4.getPredicate(), OpAnd, cond5.getPredicate());
    table->setCondition(&cond5a);
    printf("Predicate: ( f1 <4 AND (NOT(f2 >3)) \n");
    conn.startTransaction();
    execAndPrint(table);

    conn.commit();
    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    return 0;

}
예제 #11
0
void LLTabContainer::addTabPanel(LLPanel* child, 
								 const std::string& label, 
								 BOOL select, 
								 void (*on_tab_clicked)(void*, bool), 
								 void* userdata,
								 S32 indent,
								 BOOL placeholder,
								 eInsertionPoint insertion_point)
{
	if (child->getParent() == this)
	{
		// already a child of mine
		return;
	}
	const LLFontGL* font = LLResMgr::getInstance()->getRes( mIsVertical ? LLFONT_SANSSERIF : LLFONT_SANSSERIF_SMALL );

	// Store the original label for possible xml export.
	child->setLabel(label);
	std::string trimmed_label = label;
	LLStringUtil::trim(trimmed_label);

	S32 button_width = mMinTabWidth;
	if (!mIsVertical)
	{
		button_width = llclamp(font->getWidth(trimmed_label) + TAB_PADDING, mMinTabWidth, mMaxTabWidth);
	}
	
	// Tab panel
	S32 tab_panel_top;
	S32 tab_panel_bottom;
	if( getTabPosition() == LLTabContainer::TOP )
	{
		S32 tab_height = mIsVertical ? BTN_HEIGHT : TABCNTR_TAB_HEIGHT;
		tab_panel_top = getRect().getHeight() - getTopBorderHeight() - (tab_height - TABCNTR_BUTTON_PANEL_OVERLAP);	
		tab_panel_bottom = LLPANEL_BORDER_WIDTH;
	}
	else
	{
		tab_panel_top = getRect().getHeight() - getTopBorderHeight();
		tab_panel_bottom = (TABCNTR_TAB_HEIGHT - TABCNTR_BUTTON_PANEL_OVERLAP);  // Run to the edge, covering up the border
	}
	
	LLRect tab_panel_rect;
	if (mIsVertical)
	{
		tab_panel_rect = LLRect(mMinTabWidth + (LLPANEL_BORDER_WIDTH * 2) + TABCNTRV_PAD, 
								getRect().getHeight() - LLPANEL_BORDER_WIDTH,
								getRect().getWidth() - LLPANEL_BORDER_WIDTH,
								LLPANEL_BORDER_WIDTH);
	}
	else
	{
		tab_panel_rect = LLRect(LLPANEL_BORDER_WIDTH, 
								tab_panel_top,
								getRect().getWidth()-LLPANEL_BORDER_WIDTH,
								tab_panel_bottom );
	}
	child->setFollowsAll();
	child->translate( tab_panel_rect.mLeft - child->getRect().mLeft, tab_panel_rect.mBottom - child->getRect().mBottom);
	child->reshape( tab_panel_rect.getWidth(), tab_panel_rect.getHeight(), TRUE );
	// add this child later

	child->setVisible( FALSE );  // Will be made visible when selected

	mTotalTabWidth += button_width;

	// Tab button
	LLRect btn_rect;  // Note: btn_rect.mLeft is just a dummy.  Will be updated in draw().
	std::string tab_img;
	std::string tab_selected_img;
	S32 tab_fudge = 1;		//  To make new tab art look better, nudge buttons up 1 pel

	if (mIsVertical)
	{
		btn_rect.setLeftTopAndSize(TABCNTRV_PAD + LLPANEL_BORDER_WIDTH + 2,	// JC - Fudge factor
								   (getRect().getHeight() - getTopBorderHeight() - LLPANEL_BORDER_WIDTH - 1) - ((BTN_HEIGHT + TABCNTRV_PAD) * getTabCount()),
								   mMinTabWidth,
								   BTN_HEIGHT);
	}
	else if( getTabPosition() == LLTabContainer::TOP )
	{
		btn_rect.setLeftTopAndSize( 0, getRect().getHeight() - getTopBorderHeight() + tab_fudge, button_width, TABCNTR_TAB_HEIGHT );
		tab_img = "tab_top_blue.tga";
		tab_selected_img = "tab_top_selected_blue.tga";
	}
	else
	{
		btn_rect.setOriginAndSize( 0, 0 + tab_fudge, button_width, TABCNTR_TAB_HEIGHT );
		tab_img = "tab_bottom_blue.tga";
		tab_selected_img = "tab_bottom_selected_blue.tga";
	}

	LLTextBox* textbox = NULL;
	LLButton* btn = NULL;
	
	if (placeholder)
	{
		btn_rect.translate(0, -LLBUTTON_V_PAD-2);
		textbox = new LLTextBox(trimmed_label, btn_rect, trimmed_label, font);
		
		btn = new LLButton(LLStringUtil::null, LLRect(0,0,0,0));
	}
	else
	{
		if (mIsVertical)
		{
			btn = new LLButton(std::string("vert tab button"),
							   btn_rect,
							   LLStringUtil::null,
							   LLStringUtil::null, 
							   LLStringUtil::null, 
							   &LLTabContainer::onTabBtn, NULL,
							   font,
							   trimmed_label, trimmed_label);
			btn->setImages(std::string("tab_left.tga"), std::string("tab_left_selected.tga"));
			btn->setScaleImage(TRUE);
			btn->setHAlign(LLFontGL::LEFT);
			btn->setFollows(FOLLOWS_TOP | FOLLOWS_LEFT);
			btn->setTabStop(FALSE);
			if (indent)
			{
				btn->setLeftHPad(indent);
			}
		}
		else
		{
			std::string tooltip = trimmed_label;
			tooltip += "\nAlt-Left arrow for previous tab";
			tooltip += "\nAlt-Right arrow for next tab";

			btn = new LLButton(std::string(child->getName()) + " tab",
							   btn_rect, 
							   LLStringUtil::null, LLStringUtil::null, LLStringUtil::null,
							   &LLTabContainer::onTabBtn, NULL, // set userdata below
							   font,
							   trimmed_label, trimmed_label );
			btn->setVisible( FALSE );
			btn->setToolTip( tooltip );
			btn->setScaleImage(TRUE);
			btn->setImages(tab_img, tab_selected_img);

			// Try to squeeze in a bit more text
			btn->setLeftHPad( 4 );
			btn->setRightHPad( 2 );
			btn->setHAlign(LLFontGL::LEFT);
			btn->setTabStop(FALSE);
			if (indent)
			{
				btn->setLeftHPad(indent);
			}

			if( getTabPosition() == TOP )
			{
				btn->setFollowsTop();
			}
			else
			{
				btn->setFollowsBottom();
			}
		}
	}
	
	LLTabTuple* tuple = new LLTabTuple( this, child, btn, on_tab_clicked, userdata, textbox );
	insertTuple( tuple, insertion_point );

	if (textbox)
	{
		textbox->setSaveToXML(false);
		addChild( textbox, 0 );
	}
	if (btn)
	{
		btn->setSaveToXML(false);
		btn->setCallbackUserData( tuple );
		addChild( btn, 0 );
	}
	if (child)
	{
		addChild(child, 1);
	}
	
	if( select )
	{
		selectLastTab();
	}

	updateMaxScrollPos();
}