本文整理汇总了C++中ChunkManager类的典型用法代码示例。如果您正苦于以下问题:C++ ChunkManager类的具体用法?C++ ChunkManager怎么用?C++ ChunkManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChunkManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
string dbName = getDBName( ns );
string collection = cmdObj.firstElement().valuestrsafe();
string fullns = dbName + "." + collection;
BSONObj filter = cmdObj["query"].embeddedObject();
DBConfig * conf = grid.getDBConfig( dbName , false );
if ( ! conf || ! conf->isShardingEnabled() || ! conf->isSharded( fullns ) ){
ScopedDbConnection conn( conf->getPrimary() );
result.append( "n" , (double)conn->count( fullns , filter ) );
conn.done();
result.append( "ok" , 1 );
return true;
}
ChunkManager * cm = conf->getChunkManager( fullns );
massert( "how could chunk manager be null!" , cm );
vector<Chunk*> chunks;
cm->getChunksForQuery( chunks , filter );
unsigned long long total = 0;
for ( vector<Chunk*>::iterator i = chunks.begin() ; i != chunks.end() ; i++ ){
Chunk * c = *i;
total += c->countObjects();
}
result.append( "n" , (double)total );
result.append( "ok" , 1 );
return true;
}
示例2: updateNumDownloadedChunks
void TorrentFile::updateNumDownloadedChunks(ChunkManager & cman)
{
const BitSet & bs = cman.getBitSet();
Uint32 old_chunk_count = num_chunks_downloaded;
num_chunks_downloaded = 0;
Uint32 preview_range = cman.previewChunkRangeSize(*this);
bool prev = preview;
preview = true;
for (Uint32 i = first_chunk;i <= last_chunk;i++)
{
if (bs.get(i))
{
num_chunks_downloaded++;
}
else if (preview_range > 0 && i >= first_chunk && i < first_chunk + preview_range)
{
preview = false;
}
}
preview = isMultimedia() && preview;
if (num_chunks_downloaded != old_chunk_count)
tor->filePercentageChanged(this,getDownloadPercentage());
if (prev != preview)
tor->filePreviewChanged(this,preview);
}
示例3: run
void run() {
ChunkManager chunkManager;
chunkManager.setShardKey( shardKey() );
chunkManager.setSingleChunkForShards( splitPointsVector() );
set<Shard> shards;
chunkManager.getShardsForQuery( shards, query() );
BSONArrayBuilder b;
for( set<Shard>::const_iterator i = shards.begin(); i != shards.end(); ++i ) {
b << i->getName();
}
ASSERT_EQUALS( expectedShardNames(), b.arr() );
}
示例4: handleRequests
Uint32 PeerUploader::handleRequests(ChunkManager & cman)
{
Uint32 ret = uploaded;
uploaded = 0;
// if we have choked the peer do not upload
if (peer->areWeChoked())
return ret;
while (requests.size() > 0)
{
Request r = requests.front();
Chunk* c = cman.getChunk(r.getIndex());
if (c && c->getStatus() == Chunk::ON_DISK)
{
if (!peer->sendChunk(r.getIndex(),r.getOffset(),r.getLength(),c))
{
if (peer->getStats().fast_extensions)
peer->sendReject(r);
}
}
else
{
// remove requests we can't satisfy
Out(SYS_CON|LOG_DEBUG) << "Cannot satisfy request" << endl;
if (peer->getStats().fast_extensions)
peer->sendReject(r);
}
requests.pop_front();
}
return ret;
}
示例5: populateShardToChunksMap
void DistributionStatus::populateShardToChunksMap(const vector<Shard>& allShards,
const ChunkManager& chunkMgr,
ShardToChunksMap* shardToChunksMap) {
// Makes sure there is an entry in shardToChunksMap for every shard.
for (vector<Shard>::const_iterator it = allShards.begin();
it != allShards.end(); ++it) {
OwnedPointerVector<ChunkType>*& chunkList =
(*shardToChunksMap)[it->getName()];
if (chunkList == NULL) {
chunkList = new OwnedPointerVector<ChunkType>();
}
}
const ChunkMap& chunkMap = chunkMgr.getChunkMap();
for (ChunkMap::const_iterator it = chunkMap.begin(); it != chunkMap.end(); ++it) {
const ChunkPtr chunkPtr = it->second;
auto_ptr<ChunkType> chunk(new ChunkType());
chunk->setNS(chunkPtr->getns());
chunk->setMin(chunkPtr->getMin().getOwned());
chunk->setMax(chunkPtr->getMax().getOwned());
chunk->setJumbo(chunkPtr->isJumbo()); // TODO: is this reliable?
const string shardName(chunkPtr->getShard().getName());
chunk->setShard(shardName);
(*shardToChunksMap)[shardName]->push_back(chunk.release());
}
}
示例6: main
int main(int argc, const char** argv)
{
ChunkManager<uint32_t> storage;
vector<size_t> p(33);
for (int i = 1; i < p.size(); ++i) {
p[i] = storage.allocate(i);
cerr << "(" << p[i] << " " << storage.global_address(p[i]) << ") ";
}
cerr << endl;
vector< vector<size_t> > p2(33);
for (int i = 1; i < p2.size(); ++i) {
p2[i].resize(7);
for (int j = 0; j < p2[i].size(); ++j) {
p2[i][j] = storage.allocate(i);
cerr << "(" << p2[i][j] << " " << storage.global_address(p2[i][j]) << ") ";
}
cerr << endl;
}
for (int i = 1; i < p.size(); ++i) {
*reinterpret_cast<char*>(storage.global_address(p[i])) = i;
}
for (int i = 1; i < p.size(); ++i) {
cerr << *reinterpret_cast<int*>(storage.global_address(p[i])) << " ";
}
cerr << endl;
cerr << "deallocate" <<endl;
for (int i = 1; i < p2.size(); ++i) {
for (int j = 0; j < p2[i].size(); j+=2) {
cerr << i << " " << p2[i][j] << ", ";
storage.deallocate(p2[i][j]);
}
}
cerr << "p3:" << endl;
vector< vector<size_t> > p3(33);
for (int i = 1; i < p3.size(); ++i) {
p3[i].resize(10);
for (int j = 0; j < p3[i].size(); ++j) {
p3[i][j] = storage.allocate(i);
cerr << p3[i][j] << " ";
}
cerr << endl;
}
}
示例7: handleIndexWrite
void handleIndexWrite( int op , Request& r ) {
DbMessage& d = r.d();
if ( op == dbInsert ) {
while( d.moreJSObjs() ) {
BSONObj o = d.nextJsObj();
const char * ns = o["ns"].valuestr();
if ( r.getConfig()->isSharded( ns ) ) {
BSONObj newIndexKey = o["key"].embeddedObjectUserCheck();
uassert( 10205 , (string)"can't use unique indexes with sharding ns:" + ns +
" key: " + o["key"].embeddedObjectUserCheck().toString() ,
IndexDetails::isIdIndexPattern( newIndexKey ) ||
! o["unique"].trueValue() ||
r.getConfig()->getChunkManager( ns )->getShardKey().uniqueAllowd( newIndexKey ) );
ChunkManager * cm = r.getConfig()->getChunkManager( ns );
assert( cm );
for ( int i=0; i<cm->numChunks(); i++)
doWrite( op , r , cm->getChunk(i)->getShard() );
}
else {
doWrite( op , r , r.primaryShard() );
}
r.gotInsert();
}
}
else if ( op == dbUpdate ) {
throw UserException( 8050 , "can't update system.indexes" );
}
else if ( op == dbDelete ) {
// TODO
throw UserException( 8051 , "can't delete indexes on sharded collection yet" );
}
else {
log() << "handleIndexWrite invalid write op: " << op << endl;
throw UserException( 8052 , "handleIndexWrite invalid write op" );
}
}
示例8: populateShardToChunksMap
void DistributionStatus::populateShardToChunksMap(const ShardStatisticsVector& allShards,
const ChunkManager& chunkMgr,
ShardToChunksMap* shardToChunksMap) {
// Makes sure there is an entry in shardToChunksMap for every shard.
for (const auto& stat : allShards) {
(*shardToChunksMap)[stat.shardId];
}
const ChunkMap& chunkMap = chunkMgr.getChunkMap();
for (ChunkMap::const_iterator it = chunkMap.begin(); it != chunkMap.end(); ++it) {
const ChunkPtr chunkPtr = it->second;
ChunkType chunk;
chunk.setNS(chunkMgr.getns());
chunk.setMin(chunkPtr->getMin().getOwned());
chunk.setMax(chunkPtr->getMax().getOwned());
chunk.setJumbo(chunkPtr->isJumbo()); // TODO: is this reliable?
const string shardName(chunkPtr->getShardId());
chunk.setShard(shardName);
(*shardToChunksMap)[shardName].push_back(chunk);
}
}
示例9: setupChunkManager
void setupChunkManager() {
ChunkSettings chunkSettings;
chunkSettings.chunkSize = Vector2i(64, 64);
chunkSettings.tileSize = Vector2i(16, 16);
chunkSettings.tileTexSize = Vector2f(16, 16);
chunkSettings.tilesPerWidthTex = 4;
chunkSettings.scale = SCALE;
chunkSettings.world = &world;
WorldSettings worldSettings;
worldSettings.worldSize = Vector2i(16, 8);
worldSettings.chunkTexture = &blocksTexture;
worldSettings.chunkSettings = chunkSettings;
worldSizeX = chunkSettings.chunkSize.x * chunkSettings.tileSize.x * worldSettings.worldSize.x;
worldSizeY = chunkSettings.chunkSize.y * chunkSettings.tileSize.y * worldSettings.worldSize.y;
chunkManager.initialize(worldSettings);
}
示例10: _UpdatingChunksThread
void ChunkManager::_UpdatingChunksThread(void* pData)
{
ChunkManager* lpChunkManager = (ChunkManager*)pData;
lpChunkManager->UpdatingChunksThread();
}
示例11: queryOp
virtual void queryOp( Request& r ){
QueryMessage q( r.d() );
log(3) << "shard query: " << q.ns << " " << q.query << endl;
if ( q.ntoreturn == 1 && strstr(q.ns, ".$cmd") )
throw UserException( 8010 , "something is wrong, shouldn't see a command here" );
ChunkManager * info = r.getChunkManager();
assert( info );
Query query( q.query );
vector<Chunk*> shards;
info->getChunksForQuery( shards , query.getFilter() );
set<ServerAndQuery> servers;
map<string,int> serverCounts;
for ( vector<Chunk*>::iterator i = shards.begin(); i != shards.end(); i++ ){
servers.insert( ServerAndQuery( (*i)->getShard() , (*i)->getFilter() ) );
int& num = serverCounts[(*i)->getShard()];
num++;
}
if ( logLevel > 4 ){
StringBuilder ss;
ss << " shard query servers: " << servers.size() << "\n";
for ( set<ServerAndQuery>::iterator i = servers.begin(); i!=servers.end(); i++ ){
const ServerAndQuery& s = *i;
ss << " " << s.toString() << "\n";
}
log() << ss.str();
}
ClusteredCursor * cursor = 0;
BSONObj sort = query.getSort();
if ( sort.isEmpty() ){
// 1. no sort, can just hit them in serial
cursor = new SerialServerClusteredCursor( servers , q );
}
else {
int shardKeyOrder = info->getShardKey().canOrder( sort );
if ( shardKeyOrder ){
// 2. sort on shard key, can do in serial intelligently
set<ServerAndQuery> buckets;
for ( vector<Chunk*>::iterator i = shards.begin(); i != shards.end(); i++ ){
Chunk * s = *i;
buckets.insert( ServerAndQuery( s->getShard() , s->getFilter() , s->getMin() ) );
}
cursor = new SerialServerClusteredCursor( buckets , q , shardKeyOrder );
}
else {
// 3. sort on non-sharded key, pull back a portion from each server and iterate slowly
cursor = new ParallelSortClusteredCursor( servers , q , sort );
}
}
assert( cursor );
log(5) << " cursor type: " << cursor->type() << endl;
ShardedClientCursor * cc = new ShardedClientCursor( q , cursor );
if ( ! cc->sendNextBatch( r ) ){
delete( cursor );
return;
}
log(6) << "storing cursor : " << cc->getId() << endl;
cursorCache.store( cc );
}
示例12: castRay
// TODO: Should this go in chunkManager?
bool castRay(const Camera& camera, const ChunkManager& chunkManager, Coordinate& currentBlock, Coordinate& lastBlock)
{
glm::vec3 current = camera.eye;
glm::vec3 gaze = camera.gaze();
currentBlock = current;
glm::vec3 fractional = glm::fract(current);
// The direction of travel, in block coordinates
Coordinate step(glm::sign(gaze));
// The distance along gaze between consecutive blocks boundary
glm::vec3 delta = glm::length(gaze) / glm::abs(gaze);
// The distance along gaze to the first block boundary
glm::vec3 distance;
distance.x = gaze.x < 0 ? fractional.x : 1 - fractional.x;
distance.y = gaze.y < 0 ? fractional.y : 1 - fractional.y;
distance.z = gaze.z < 0 ? fractional.z : 1 - fractional.z;
distance *= delta;
do
{
// Travel the smallest distance necessary to hit the next block
// Intersects x-wall first
if (distance.x <= distance.y && distance.x <= distance.z)
{
lastBlock = currentBlock;
current += distance.x * gaze;
currentBlock.x += step.x;
distance -= glm::vec3(distance.x);
distance.x = delta.x;
}
else if (distance.y <= distance.x && distance.y <= distance.z)
{
lastBlock = currentBlock;
current += distance.y * gaze;
currentBlock.y += step.y;
distance -= glm::vec3(distance.y);
distance.y = delta.y;
}
else if (distance.z <= distance.x && distance.z <= distance.y)
{
lastBlock = currentBlock;
current += distance.z * gaze;
currentBlock.z += step.z;
distance -= glm::vec3(distance.z);
distance.z = delta.z;
}
else
{
// Numerical error?
assert(false);
}
// Only look for intersections within a certain range of the camera
if (glm::length(current - camera.eye) > MAX_TARGET_DISTANCE)
return false;
} while (chunkManager.isTransparent(currentBlock));
return true;
}
示例13: compatibleWith
bool ChunkManager::compatibleWith(const ChunkManager& other, const string& shardName) const {
// Return true if the shard version is the same in the two chunk managers
// TODO: This doesn't need to be so strong, just major vs
return other.getVersion(shardName).equals(getVersion(shardName));
}
示例14: _UpdateChunksThread
void ChunkManager::_UpdateChunksThread(void* pData) {
ChunkManager* chunkManager = (ChunkManager*)pData;
chunkManager->UpdateChunksThread();
}
示例15: update
void Player::update(float32 deltaSeconds)
{
const static float32 JUMP_POWER = 7.0f;
const static float32 SPEED = 5.0f;
const static float32 ROTATE_SPEED = 0.01f;
const static int MAX_JUMP_FRAMES = 15;
m_currentPosition = glm::vec3(transform.xPos, transform.yPos, transform.zPos);
m_lastPosition = m_currentPosition;
// Get current chunk
ChunkManager* cm = ChunkManager::instance();
m_chunkValid = cm->getChunkHandle(cm->getCurrentChunk(m_currentPosition), m_currentChunk);
// DONT UPDATE ME IF MY CHUNK ISNT VALID YET GOOOSH
if (!m_chunkValid) {
return;
}
static bool hasLanded = false;
float32 dx = 0;
float32 dy = 0;
float32 dz = 0;
if (m_forwardPressed) {
--dz;
}
if (m_backwardPressed) {
++dz;
}
if (m_leftPressed) {
--dx;
}
if (m_rightPressed) {
++dx;
}
glm::vec3 displacement = glm::rotate(transform.rotation, glm::vec3(dx, 0, dz));
displacement.y = 0;
displacement = glm::normalize(displacement);
displacement *= SPEED * deltaSeconds;
// Numerical approximation via Euler Integration
dy = m_velocityY * deltaSeconds;
m_velocityY += GRAVITY * deltaSeconds;
//displacement.y = dy;
//transform.translate(displacement);
if (dx || dz) {
transform.translate(displacement);
}
if (!m_glueToGround) {
transform.translate(0, dy, 0);
}
if (dx || (dy && !m_glueToGround) || dz) {
m_movedDuringFrame = true;
}
else {
m_movedDuringFrame = false;
}
//transform.translateLocal(dx, 0, dz);
//transform.translate(0, dy, 0);
// Apply jump
if (m_jumpPressed) {
// Apply impulse and cancel gravity
m_velocityY = JUMP_POWER;
m_jumpPressed = false;
m_glueToGround = false;
}
//if (m_jumpPressed) {
// if (!m_isJumping && hasLanded)
// {
// m_isJumping = true;
// hasLanded = false;
// }
//}
//
//if(m_ready && !m_isJumping)
// dy += GRAVITY * deltaSeconds;
//else if (m_ready && m_isJumping)
//{
// dy -= GRAVITY * deltaSeconds;
// m_jumpedFrames++;
//
// if (m_jumpedFrames > MAX_JUMP_FRAMES)
// {
// m_jumpedFrames = 0;
// m_isJumping = false;
// }
//}
glm::vec3 deltaPos(dx, dy, dz);
deltaPos = (glm::normalize(deltaPos) * SPEED * deltaSeconds);
//.........这里部分代码省略.........