Merge pull request #674 from alexmiller-apple/glibcxx-debug-fixes

Fix bugs uncovered by -D_GLIBCXX_DEBUG
This commit is contained in:
A.J. Beamon 2018-08-09 08:18:51 -07:00 committed by GitHub
commit 3535ddad80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 67 additions and 38 deletions

View File

@ -24,6 +24,7 @@
#include "DatabaseContext.h"
#include "StatusClient.h"
#include "MonitorLeader.h"
#include "flow/Util.h"
class RYWImpl {
public:
@ -936,16 +937,12 @@ public:
for( int i = 0; i < itCopy->value.size(); i++ ) {
if(itCopy->value[i]->onChangeTrigger.isSet()) {
if( i < itCopy->value.size() - 1 )
std::swap(itCopy->value[i--], itCopy->value.back());
itCopy->value.pop_back();
swapAndPop(&itCopy->value, i--);
} else if( !valueKnown ||
(itCopy->value[i]->setPresent && (itCopy->value[i]->setValue.present() != val.present() || (val.present() && itCopy->value[i]->setValue.get() != val.get()))) ||
(itCopy->value[i]->valuePresent && (itCopy->value[i]->value.present() != val.present() || (val.present() && itCopy->value[i]->value.get() != val.get()))) ) {
itCopy->value[i]->onChangeTrigger.send(Void());
if( i < itCopy->value.size() - 1 )
std::swap(itCopy->value[i--], itCopy->value.back());
itCopy->value.pop_back();
swapAndPop(&itCopy->value, i--);
} else {
itCopy->value[i]->setPresent = true;
itCopy->value[i]->setValue = val.cast_to<Value>();

View File

@ -84,7 +84,7 @@ bool IReplicationPolicy::validateFull(
auto missingEntry = totalSolution[lastSolutionIndex];
totalSolution[lastSolutionIndex] = totalSolution.back();
totalSolution.pop_back();
for (int index = 0; index < solutionSet.size(); index ++) {
for (int index = 0; index < solutionSet.size() && index < totalSolution.size(); index ++) {
if (g_replicationdebug > 3) {
auto fromServer = fromServers->getRecordViaEntry(missingEntry);
printf("Test remove entry: %s test:%3d of%3lu\n", fromServers->getEntryInfo(missingEntry).c_str(), index+1, solutionSet.size());

View File

@ -20,6 +20,7 @@
#include "simulator.h"
#include "flow/IThreadPool.h"
#include "flow/Util.h"
#include "IAsyncFile.h"
#include "AsyncFileCached.actor.h"
#include "AsyncFileNonDurable.actor.h"
@ -1226,8 +1227,7 @@ public:
auto processes = getAllProcesses();
for( int i = 0; i < processes.size(); i++ ) {
if( processes[i]->locality.zoneId() != zoneId || processes[i]->rebooting ) {
std::swap(processes[i--], processes.back());
processes.pop_back();
swapAndPop(&processes, i--);
}
}
if( processes.size() )

View File

@ -38,6 +38,7 @@
#include "fdbrpc/Replication.h"
#include "fdbrpc/ReplicationUtils.h"
#include "fdbclient/KeyBackedTypes.h"
#include "flow/Util.h"
void failAfter( Future<Void> trigger, Endpoint e );
@ -1194,8 +1195,7 @@ void checkOutstandingRecruitmentRequests( ClusterControllerData* self ) {
RecruitFromConfigurationRequest& req = self->outstandingRecruitmentRequests[i];
try {
req.reply.send( self->findWorkersForConfiguration( req ) );
std::swap( self->outstandingRecruitmentRequests[i--], self->outstandingRecruitmentRequests.back() );
self->outstandingRecruitmentRequests.pop_back();
swapAndPop( &self->outstandingRecruitmentRequests, i-- );
} catch (Error& e) {
if (e.code() == error_code_no_more_servers || e.code() == error_code_operation_failed) {
TraceEvent(SevWarn, "RecruitTLogMatchingSetNotAvailable", self->id).error(e);
@ -1212,8 +1212,7 @@ void checkOutstandingRemoteRecruitmentRequests( ClusterControllerData* self ) {
RecruitRemoteFromConfigurationRequest& req = self->outstandingRemoteRecruitmentRequests[i];
try {
req.reply.send( self->findRemoteWorkersForConfiguration( req ) );
std::swap( self->outstandingRemoteRecruitmentRequests[i--], self->outstandingRemoteRecruitmentRequests.back() );
self->outstandingRemoteRecruitmentRequests.pop_back();
swapAndPop( &self->outstandingRemoteRecruitmentRequests, i-- );
} catch (Error& e) {
if (e.code() == error_code_no_more_servers || e.code() == error_code_operation_failed) {
TraceEvent(SevWarn, "RecruitRemoteTLogMatchingSetNotAvailable", self->id).error(e);
@ -1231,8 +1230,7 @@ void checkOutstandingStorageRequests( ClusterControllerData* self ) {
try {
if(req.second < now()) {
req.first.reply.sendError(timed_out());
std::swap( self->outstandingStorageRequests[i--], self->outstandingStorageRequests.back() );
self->outstandingStorageRequests.pop_back();
swapAndPop( &self->outstandingStorageRequests, i-- );
} else {
if(!self->gotProcessClasses && !req.first.criticalRecruitment)
throw no_more_servers();
@ -1242,8 +1240,7 @@ void checkOutstandingStorageRequests( ClusterControllerData* self ) {
rep.worker = worker.first;
rep.processClass = worker.second;
req.first.reply.send( rep );
std::swap( self->outstandingStorageRequests[i--], self->outstandingStorageRequests.back() );
self->outstandingStorageRequests.pop_back();
swapAndPop( &self->outstandingStorageRequests, i-- );
}
} catch (Error& e) {
if (e.code() == error_code_no_more_servers) {

View File

@ -706,8 +706,7 @@ struct DDTeamCollection {
while( similarTeams.size() && randomTeams.size() < SERVER_KNOBS->BEST_TEAM_OPTION_COUNT ) {
int randomTeam = g_random->randomInt( 0, similarTeams.size() );
randomTeams.push_back( std::make_pair( SOME_SHARED, similarTeams[randomTeam] ) );
std::swap( similarTeams[randomTeam], similarTeams.back() );
similarTeams.pop_back();
swapAndPop( &similarTeams, randomTeam );
}
}
}

View File

@ -20,6 +20,7 @@
#include "flow/actorcompiler.h"
#include "flow/ActorCollection.h"
#include "flow/Util.h"
#include "fdbrpc/sim_validation.h"
#include "fdbclient/SystemData.h"
#include "DataDistribution.h"
@ -535,8 +536,7 @@ struct DDQueueData {
} else {
for(int i = 0; i < input.completeSources.size(); i++) {
if(std::find(src.begin(), src.end(), input.completeSources[i]) == src.end()) {
std::swap(input.completeSources[i--], input.completeSources.back());
input.completeSources.pop_back();
swapAndPop(&input.completeSources, i--);
}
}
}

View File

@ -19,6 +19,7 @@
*/
#include "flow/actorcompiler.h"
#include "flow/Util.h"
#include "fdbrpc/FailureMonitor.h"
#include "fdbclient/SystemData.h"
#include "MoveKeys.h"
@ -470,8 +471,7 @@ ACTOR Future<Void> finishMoveKeys( Database occ, KeyRange keys, vector<UID> dest
} else {
for(int i = 0; i < completeSrc.size(); i++) {
if(!srcSet.count(completeSrc[i])) {
std::swap(completeSrc[i--], completeSrc.back());
completeSrc.pop_back();
swapAndPop(&completeSrc, i--);
}
}
}
@ -520,8 +520,7 @@ ACTOR Future<Void> finishMoveKeys( Database occ, KeyRange keys, vector<UID> dest
for(int i = 0; i < completeSrc.size(); i++) {
if(!srcSet.count(completeSrc[i])) {
std::swap(completeSrc[i--], completeSrc.back());
completeSrc.pop_back();
swapAndPop(&completeSrc, i--);
}
}

View File

@ -25,6 +25,7 @@
#include "flow/IndexedSet.h"
#include "flow/Hash3.h"
#include "flow/ActorCollection.h"
#include "flow/Util.h"
#include "fdbclient/Atomic.h"
#include "fdbclient/KeyRangeMap.h"
#include "fdbclient/SystemData.h"
@ -3072,8 +3073,7 @@ ACTOR Future<Void> waitMetrics( StorageServerMetrics* self, WaitMetricsRequest r
auto &x = i->value();
for( int j = 0; j < x.size(); j++ ) {
if( x[j] == change ) {
std::swap( x[j], x.back() );
x.pop_back();
swapAndPop(&x, j);
break;
}
}

View File

@ -37,7 +37,7 @@ Key MemoryKeyValueStore::getKey(KeySelectorRef selector) const {
//Update the iterator position if necessary based on the value of orEqual
int count = 0;
if(selector.offset <= 0) {
if((selector.getKey() == mapItr->first && !selector.orEqual) || selector.getKey() != mapItr->first) {
if(mapItr == store.end() || selector.getKey() != mapItr->first || !selector.orEqual) {
if(mapItr == store.begin())
return startKey();
@ -45,10 +45,10 @@ Key MemoryKeyValueStore::getKey(KeySelectorRef selector) const {
}
}
else {
if(selector.getKey() == mapItr->first && selector.orEqual) {
if(mapItr == store.end())
return endKey();
if(mapItr == store.end())
return endKey();
if(selector.getKey() == mapItr->first && selector.orEqual) {
mapItr++;
}

View File

@ -247,7 +247,6 @@ struct RemoveServersSafelyWorkload : TestWorkload {
int randomIndex;
bool bCanKillProcess;
ISimulator::ProcessInfo* randomProcess;
auto deadProcess = processesDead.back();
for (int killsLeft = killProcArray.size(); killsLeft > 0; killsLeft --)
{
// Select a random kill process

View File

@ -84,8 +84,12 @@ public:
template <class C>
void randomShuffle( C& container ) {
int s = (int)container.size();
for(int i=0; i<s; i++)
std::swap( container[i], container[ randomInt( i, s ) ] );
for(int i=0; i<s; i++) {
int j = randomInt( i, s );
if (i != j) {
std::swap( container[i], container[j] );
}
}
}
bool coinflip() { return (this->random01() < 0.5); }

35
flow/Util.h Normal file
View File

@ -0,0 +1,35 @@
/*
* Util.h
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _FLOW_UTIL_H_
#define _FLOW_UTIL_H_
#pragma once
template <typename C>
void swapAndPop(C* container, int index) {
if (index != container->size()-1) {
using std::swap;
swap((*container)[index], container->back());
}
container->pop_back();
}
#endif // _FLOW_UTIL_H_

View File

@ -31,6 +31,7 @@
#include "actorcompiler.h"
#include "Knobs.h"
#include "flow/Util.h"
#pragma warning( disable: 4355 ) // 'this' : used in base member initializer list
ACTOR template<class T, class X>
@ -1464,8 +1465,7 @@ public:
return false;
}
else if(!futures[i].isError()) {
std::swap(futures[i], futures.back());
futures.pop_back();
swapAndPop(&futures, i);
}
}
return true;
@ -1481,8 +1481,7 @@ public:
void cleanup() {
for( int i = 0; i < futures.size(); i++ ) {
if( futures[i].isReady() && !futures[i].isError() ) {
std::swap(futures[i--], futures.back());
futures.pop_back();
swapAndPop(&futures, i--);
}
}
}