Use 64 bits random bytes as GID

This change replaces the current 64 bit sequential GID with 64 bits
random bytes GID in an attempt to support persistent GID. Internally,
the GID is stored as uint64_t. For human representation and RPC
interface, GID is represented as 16 bytes hex string. For console
readout, 16 bytes are too long, so it is abbreviated to first 6 bytes.
When querying GID in RPC calls, user can speicfy the prefix of GID as
long as the prefix is shared by more than 1 GID entries.
This commit is contained in:
Tatsuhiro Tsujikawa 2012-12-16 16:00:18 +09:00
parent 04586f50b1
commit b9da9d4ed3
32 changed files with 627 additions and 192 deletions

View file

@ -33,7 +33,6 @@ private:
public:
void setUp()
{
RequestGroup::resetGIDCounter();
option_.reset(new Option());
}
@ -49,8 +48,10 @@ CPPUNIT_TEST_SUITE_REGISTRATION( RequestGroupManTest );
void RequestGroupManTest::testIsSameFileBeingDownloaded()
{
SharedHandle<RequestGroup> rg1(new RequestGroup(util::copy(option_)));
SharedHandle<RequestGroup> rg2(new RequestGroup(util::copy(option_)));
SharedHandle<RequestGroup> rg1(new RequestGroup(GroupId::create(),
util::copy(option_)));
SharedHandle<RequestGroup> rg2(new RequestGroup(GroupId::create(),
util::copy(option_)));
SharedHandle<DownloadContext> dctx1
(new DownloadContext(0, 0, "aria2.tar.bz2"));
@ -118,51 +119,71 @@ void RequestGroupManTest::testLoadServerStat()
void RequestGroupManTest::testChangeReservedGroupPosition()
{
SharedHandle<RequestGroup> gs[] = {
SharedHandle<RequestGroup>(new RequestGroup(util::copy(option_))),
SharedHandle<RequestGroup>(new RequestGroup(util::copy(option_))),
SharedHandle<RequestGroup>(new RequestGroup(util::copy(option_))),
SharedHandle<RequestGroup>(new RequestGroup(util::copy(option_)))
SharedHandle<RequestGroup>(new RequestGroup(GroupId::create(),
util::copy(option_))),
SharedHandle<RequestGroup>(new RequestGroup(GroupId::create(),
util::copy(option_))),
SharedHandle<RequestGroup>(new RequestGroup(GroupId::create(),
util::copy(option_))),
SharedHandle<RequestGroup>(new RequestGroup(GroupId::create(),
util::copy(option_)))
};
std::vector<SharedHandle<RequestGroup> > groups(vbegin(gs), vend(gs));
RequestGroupMan rm(groups, 0, option_.get());
CPPUNIT_ASSERT_EQUAL
((size_t)0, rm.changeReservedGroupPosition(1, 0, RequestGroupMan::POS_SET));
((size_t)0, rm.changeReservedGroupPosition(gs[0]->getGID(),
0, RequestGroupMan::POS_SET));
CPPUNIT_ASSERT_EQUAL
((size_t)1, rm.changeReservedGroupPosition(1, 1, RequestGroupMan::POS_SET));
((size_t)1, rm.changeReservedGroupPosition(gs[0]->getGID(),
1, RequestGroupMan::POS_SET));
CPPUNIT_ASSERT_EQUAL
((size_t)3, rm.changeReservedGroupPosition(1, 10,RequestGroupMan::POS_SET));
((size_t)3, rm.changeReservedGroupPosition(gs[0]->getGID(),
10,RequestGroupMan::POS_SET));
CPPUNIT_ASSERT_EQUAL
((size_t)0, rm.changeReservedGroupPosition(1,-10,RequestGroupMan::POS_SET));
((size_t)0, rm.changeReservedGroupPosition(gs[0]->getGID(),
-10, RequestGroupMan::POS_SET));
CPPUNIT_ASSERT_EQUAL
((size_t)1, rm.changeReservedGroupPosition(2, 0, RequestGroupMan::POS_CUR));
((size_t)1, rm.changeReservedGroupPosition(gs[1]->getGID(),
0, RequestGroupMan::POS_CUR));
CPPUNIT_ASSERT_EQUAL
((size_t)2, rm.changeReservedGroupPosition(2, 1, RequestGroupMan::POS_CUR));
((size_t)2, rm.changeReservedGroupPosition(gs[1]->getGID(),
1, RequestGroupMan::POS_CUR));
CPPUNIT_ASSERT_EQUAL
((size_t)1, rm.changeReservedGroupPosition(2, -1,RequestGroupMan::POS_CUR));
((size_t)1, rm.changeReservedGroupPosition(gs[1]->getGID(),
-1,RequestGroupMan::POS_CUR));
CPPUNIT_ASSERT_EQUAL
((size_t)0, rm.changeReservedGroupPosition(2,-10,RequestGroupMan::POS_CUR));
((size_t)0, rm.changeReservedGroupPosition(gs[1]->getGID(),
-10, RequestGroupMan::POS_CUR));
CPPUNIT_ASSERT_EQUAL
((size_t)1, rm.changeReservedGroupPosition(2, 1, RequestGroupMan::POS_CUR));
((size_t)1, rm.changeReservedGroupPosition(gs[1]->getGID(),
1, RequestGroupMan::POS_CUR));
CPPUNIT_ASSERT_EQUAL
((size_t)3, rm.changeReservedGroupPosition(2, 10,RequestGroupMan::POS_CUR));
((size_t)3, rm.changeReservedGroupPosition(gs[1]->getGID(),
10, RequestGroupMan::POS_CUR));
CPPUNIT_ASSERT_EQUAL
((size_t)1, rm.changeReservedGroupPosition(2, -2,RequestGroupMan::POS_CUR));
((size_t)1, rm.changeReservedGroupPosition(gs[1]->getGID(),
-2,RequestGroupMan::POS_CUR));
CPPUNIT_ASSERT_EQUAL
((size_t)3, rm.changeReservedGroupPosition(4, 0, RequestGroupMan::POS_END));
((size_t)3, rm.changeReservedGroupPosition(gs[3]->getGID(),
0, RequestGroupMan::POS_END));
CPPUNIT_ASSERT_EQUAL
((size_t)2, rm.changeReservedGroupPosition(4, -1,RequestGroupMan::POS_END));
((size_t)2, rm.changeReservedGroupPosition(gs[3]->getGID(),
-1,RequestGroupMan::POS_END));
CPPUNIT_ASSERT_EQUAL
((size_t)0, rm.changeReservedGroupPosition(4,-10,RequestGroupMan::POS_END));
((size_t)0, rm.changeReservedGroupPosition(gs[3]->getGID(),
-10, RequestGroupMan::POS_END));
CPPUNIT_ASSERT_EQUAL
((size_t)3, rm.changeReservedGroupPosition(4, 10,RequestGroupMan::POS_END));
((size_t)3, rm.changeReservedGroupPosition(gs[3]->getGID(),
10, RequestGroupMan::POS_END));
CPPUNIT_ASSERT_EQUAL((size_t)4, rm.getReservedGroups().size());
try {
rm.changeReservedGroupPosition(5, 0, RequestGroupMan::POS_CUR);
rm.changeReservedGroupPosition(GroupId::create()->getNumericId(),
0, RequestGroupMan::POS_CUR);
CPPUNIT_FAIL("exception must be thrown.");
} catch(RecoverableException& e) {
// success