BOOL CImageList::Write( CArchive *pArchive ) /******************************************/ { ASSERT( pArchive != NULL ); CArchiveStream ars( pArchive ); return( ::ImageList_Write( m_hImageList, &ars ) ); }
BOOL CImageList::Read( CArchive *pArchive ) /*****************************************/ { ASSERT( pArchive != NULL ); CArchiveStream ars( pArchive ); return( Attach( ::ImageList_Read( &ars ) ) ); }
void mexFunction(const int nlhs_, mxArray *plhs_[], const int nrhs_, const mxArray *prhs_[]) { if (nrhs_ != 5 ) mexErrMsgTxt( "Wrong number of input arguments." ); if (nlhs_ > 1 ) mexErrMsgTxt( "Too many output arguments." ); { double n; logp_data data; data.w=1./mxGetScalar(prhs_[0]); data.a0=mxGetScalar(prhs_[1]); data.a1=mxGetScalar(prhs_[2]); n=mxGetScalar(prhs_[4]); data.s=1./mxGetScalar(prhs_[3])*n; data.a=data.a0-n*data.a1; plhs_[0]=mxCreateDoubleMatrix(1,1,mxREAL); *mxGetPr(plhs_[0])= exp(-ars(log(data.w),log(1+1/sqrt(data.a0)),logp,&data)); } return; }
StatusWith<std::vector<ClusterClientCursorParams::RemoteCursor>> establishCursors( OperationContext* opCtx, executor::TaskExecutor* executor, const NamespaceString& nss, const ReadPreferenceSetting readPref, const std::vector<std::pair<ShardId, BSONObj>>& remotes, bool allowPartialResults, BSONObj* viewDefinition) { // Construct the requests std::vector<AsyncRequestsSender::Request> requests; for (const auto& remote : remotes) { requests.emplace_back(remote.first, remote.second); } // Send the requests AsyncRequestsSender ars(opCtx, executor, nss.db().toString(), std::move(requests), readPref, Shard::RetryPolicy::kIdempotent); // Get the responses std::vector<ClusterClientCursorParams::RemoteCursor> remoteCursors; Status status = Status::OK(); while (!ars.done()) { auto response = ars.next(); StatusWith<CursorResponse> swCursorResponse( response.swResponse.isOK() ? CursorResponse::parseFromBSON(response.swResponse.getValue().data) : response.swResponse.getStatus()); if (swCursorResponse.isOK()) { remoteCursors.emplace_back(std::move(response.shardId), std::move(*response.shardHostAndPort), std::move(swCursorResponse.getValue())); continue; } // In the case a read is performed against a view, the shard primary can return an error // indicating that the underlying collection may be sharded. When this occurs the return // message will include an expanded view definition and collection namespace which we // need to store. This allows for a second attempt at the read directly against the // underlying collection. if (swCursorResponse.getStatus() == ErrorCodes::CommandOnShardedViewNotSupportedOnMongod) { auto& responseObj = response.swResponse.getValue().data; if (!responseObj.hasField("resolvedView")) { status = Status(ErrorCodes::InternalError, str::stream() << "Missing field 'resolvedView' in document: " << responseObj); break; } auto resolvedViewObj = responseObj.getObjectField("resolvedView"); if (resolvedViewObj.isEmpty()) { status = Status(ErrorCodes::InternalError, str::stream() << "Field 'resolvedView' must be an object: " << responseObj); break; } status = std::move(swCursorResponse.getStatus()); if (viewDefinition) { *viewDefinition = BSON("resolvedView" << resolvedViewObj.getOwned()); } break; } // Unreachable host errors are swallowed if the 'allowPartialResults' option is set. if (allowPartialResults) { continue; } status = std::move(swCursorResponse.getStatus()); break; } // If one of the remotes had an error, we make a best effort to finish retrieving responses for // other requests that were already sent, so that we can send killCursors to any cursors that we // know were established. if (!status.isOK()) { // Do not schedule any new requests. ars.stopRetrying(); // Collect responses from all requests that were already sent. while (!ars.done()) { auto response = ars.next(); // Check if the response contains an established cursor, and if so, store it. StatusWith<CursorResponse> swCursorResponse( response.swResponse.isOK() ? CursorResponse::parseFromBSON(response.swResponse.getValue().data) : response.swResponse.getStatus()); if (swCursorResponse.isOK()) { remoteCursors.emplace_back(std::move(response.shardId), *response.shardHostAndPort, std::move(swCursorResponse.getValue())); } } // Schedule killCursors against all cursors that were established. for (const auto& remoteCursor : remoteCursors) { BSONObj cmdObj = KillCursorsRequest(nss, {remoteCursor.cursorResponse.getCursorId()}).toBSON(); executor::RemoteCommandRequest request( remoteCursor.hostAndPort, nss.db().toString(), cmdObj, opCtx); // We do not process the response to the killCursors request (we make a good-faith // attempt at cleaning up the cursors, but ignore any returned errors). executor ->scheduleRemoteCommand( request, [](const executor::TaskExecutor::RemoteCommandCallbackArgs& cbData) {}) .status_with_transitional_ignore(); } return status; } return std::move(remoteCursors); }
std::vector<AsyncRequestsSender::Response> gatherResponses( OperationContext* opCtx, StringData dbName, const ReadPreferenceSetting& readPref, Shard::RetryPolicy retryPolicy, const std::vector<AsyncRequestsSender::Request>& requests) { // Send the requests. MultiStatementTransactionRequestsSender ars( opCtx, Grid::get(opCtx)->getExecutorPool()->getArbitraryExecutor(), dbName, requests, readPref, retryPolicy); // Get the responses. std::vector<AsyncRequestsSender::Response> responses; // Stores results by ShardId bool atLeastOneSucceeded = false; boost::optional<Status> implicitCreateErrorStatus; while (!ars.done()) { auto response = ars.next(); auto status = response.swResponse.getStatus(); if (status.isOK()) { // We successfully received a response. // Check for special errors that require throwing out any accumulated results. auto& responseObj = response.swResponse.getValue().data; status = getStatusFromCommandResult(responseObj); if (status.isOK()) { atLeastOneSucceeded = true; } // Failing to establish a consistent shardVersion means no results should be examined. if (ErrorCodes::isStaleShardVersionError(status.code())) { uassertStatusOK(status.withContext(str::stream() << "got stale shardVersion response from shard " << response.shardId << " at host " << response.shardHostAndPort->toString())); } if (ErrorCodes::StaleDbVersion == status) { uassertStatusOK(status.withContext( str::stream() << "got stale databaseVersion response from shard " << response.shardId << " at host " << response.shardHostAndPort->toString())); } // In the case a read is performed against a view, the server can return an error // indicating that the underlying collection may be sharded. When this occurs the return // message will include an expanded view definition and collection namespace. We pass // the definition back to the caller by throwing the error. This allows the caller to // rewrite the request as an aggregation and retry it. if (ErrorCodes::CommandOnShardedViewNotSupportedOnMongod == status) { uassertStatusOK(status); } if (ErrorCodes::CannotImplicitlyCreateCollection == status) { implicitCreateErrorStatus = status; } } responses.push_back(std::move(response)); } // TODO: This should not be needed once we get better targetting with SERVER-32723. // Some commands are sent with allowImplicit: false to all shards and expect only some of // them to succeed. if (implicitCreateErrorStatus && !atLeastOneSucceeded) { uassertStatusOK(*implicitCreateErrorStatus); } return responses; }
std::vector<RemoteCursor> establishCursors(OperationContext* opCtx, executor::TaskExecutor* executor, const NamespaceString& nss, const ReadPreferenceSetting readPref, const std::vector<std::pair<ShardId, BSONObj>>& remotes, bool allowPartialResults, Shard::RetryPolicy retryPolicy) { // Construct the requests std::vector<AsyncRequestsSender::Request> requests; for (const auto& remote : remotes) { requests.emplace_back(remote.first, remote.second); } // Send the requests MultiStatementTransactionRequestsSender ars( opCtx, executor, nss.db().toString(), std::move(requests), readPref, retryPolicy); std::vector<RemoteCursor> remoteCursors; try { // Get the responses while (!ars.done()) { try { auto response = ars.next(); // Note the shardHostAndPort may not be populated if there was an error, so be sure // to do this after parsing the cursor response to ensure the response was ok. // Additionally, be careful not to push into 'remoteCursors' until we are sure we // have a valid cursor, since the error handling path will attempt to clean up // anything in 'remoteCursors' auto cursors = CursorResponse::parseFromBSONMany( uassertStatusOK(std::move(response.swResponse)).data); for (auto& cursor : cursors) { if (cursor.isOK()) { RemoteCursor remoteCursor; remoteCursor.setCursorResponse(std::move(cursor.getValue())); remoteCursor.setShardId(std::move(response.shardId)); remoteCursor.setHostAndPort(*response.shardHostAndPort); remoteCursors.push_back(std::move(remoteCursor)); } } // Throw if there is any error and then the catch block below will do the cleanup. for (auto& cursor : cursors) { uassertStatusOK(cursor.getStatus()); } } catch (const DBException& ex) { // Retriable errors are swallowed if 'allowPartialResults' is true. if (allowPartialResults && std::find(RemoteCommandRetryScheduler::kAllRetriableErrors.begin(), RemoteCommandRetryScheduler::kAllRetriableErrors.end(), ex.code()) != RemoteCommandRetryScheduler::kAllRetriableErrors.end()) { continue; } throw; // Fail this loop. } } return remoteCursors; } catch (const DBException&) { // If one of the remotes had an error, we make a best effort to finish retrieving responses // for other requests that were already sent, so that we can send killCursors to any cursors // that we know were established. try { // Do not schedule any new requests. ars.stopRetrying(); // Collect responses from all requests that were already sent. while (!ars.done()) { auto response = ars.next(); // Check if the response contains an established cursor, and if so, store it. StatusWith<CursorResponse> swCursorResponse( response.swResponse.isOK() ? CursorResponse::parseFromBSON(response.swResponse.getValue().data) : response.swResponse.getStatus()); if (swCursorResponse.isOK()) { RemoteCursor cursor; cursor.setShardId(std::move(response.shardId)); cursor.setHostAndPort(*response.shardHostAndPort); cursor.setCursorResponse(std::move(swCursorResponse.getValue())); remoteCursors.push_back(std::move(cursor)); } } // Schedule killCursors against all cursors that were established. killRemoteCursors(opCtx, executor, std::move(remoteCursors), nss); } catch (const DBException&) { // Ignore the new error and rethrow the original one. } throw; } }