Skip to content

Commit

Permalink
SERVER-13643 RIP BSONElementManipulator
Browse files Browse the repository at this point in the history
If you really need to manipulate a BSONElement, do your own const_casting
  • Loading branch information
RedBeard0531 committed May 1, 2014
1 parent 89b89da commit 1f9286c
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 127 deletions.
13 changes: 7 additions & 6 deletions src/mongo/db/catalog/index_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
#include "mongo/db/index_legacy.h"
#include "mongo/db/index_names.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/jsobjmanipulator.h"
#include "mongo/db/keypattern.h"
#include "mongo/db/kill_current_op.h"
#include "mongo/db/ops/delete.h"
Expand Down Expand Up @@ -962,7 +961,9 @@ namespace mongo {
return toReturn;
}

void IndexCatalog::updateTTLSetting( const IndexDescriptor* idx, long long newExpireSeconds ) {
void IndexCatalog::updateTTLSetting( TransactionExperiment* txn,
const IndexDescriptor* idx,
long long newExpireSeconds ) {
IndexDetails* indexDetails = _getIndexDetails( idx );

const BSONElement oldExpireSecs =
Expand All @@ -971,19 +972,19 @@ namespace mongo {
// Important that we set the new value in-place. We are writing directly to the
// object here so must be careful not to overwrite with a longer numeric type.

BSONElementManipulator manip( oldExpireSecs );
char* nonConstPtr = const_cast<char*>(oldExpireSecs.value());
switch( oldExpireSecs.type() ) {
case EOO:
massert( 16631, "index does not have an 'expireAfterSeconds' field", false );
break;
case NumberInt:
manip.SetInt( static_cast<int>( newExpireSeconds ) );
*txn->writing(reinterpret_cast<int*>(nonConstPtr)) = newExpireSeconds;
break;
case NumberDouble:
manip.SetNumber( static_cast<double>( newExpireSeconds ) );
*txn->writing(reinterpret_cast<double*>(nonConstPtr)) = newExpireSeconds;
break;
case NumberLong:
manip.SetLong( newExpireSeconds );
*txn->writing(reinterpret_cast<long long*>(nonConstPtr)) = newExpireSeconds;
break;
default:
massert( 16632, "current 'expireAfterSeconds' is not a number", false );
Expand Down
4 changes: 3 additions & 1 deletion src/mongo/db/catalog/index_catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ namespace mongo {
* The specified index must already contain an expireAfterSeconds field, and the value in
* that field and newExpireSecs must both be numeric.
*/
void updateTTLSetting( const IndexDescriptor* idx, long long newExpireSeconds );
void updateTTLSetting( TransactionExperiment* txn,
const IndexDescriptor* idx,
long long newExpireSeconds );

bool isMultikey( const IndexDescriptor* idex );

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/dbcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ namespace mongo {
if ( oldExpireSecs != newExpireSecs ) {
// change expireAfterSeconds
result.appendAs( oldExpireSecs, "expireAfterSeconds_old" );
coll->getIndexCatalog()->updateTTLSetting( idx, newExpireSecs.numberLong() );
coll->getIndexCatalog()->updateTTLSetting( &txn, idx, newExpireSecs.numberLong() );
result.appendAs( newExpireSecs , "expireAfterSeconds_new" );
}
}
Expand Down
17 changes: 0 additions & 17 deletions src/mongo/db/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
#include "mongo/db/storage/mmap_v1/dur_transaction.h"
#include "mongo/db/instance.h"
#include "mongo/db/introspect.h"
#include "mongo/db/jsobjmanipulator.h"
#include "mongo/db/json.h"
#include "mongo/db/kill_current_op.h"
#include "mongo/db/lasterror.h"
Expand Down Expand Up @@ -115,22 +114,6 @@ namespace mongo {

MONGO_FP_DECLARE(rsStopGetMore);

void BSONElementManipulator::SetNumber(double d) {
if ( _element.type() == NumberDouble )
*getDur().writing( reinterpret_cast< double * >( value() ) ) = d;
else if ( _element.type() == NumberInt )
*getDur().writing( reinterpret_cast< int * >( value() ) ) = (int) d;
else verify(0);
}
void BSONElementManipulator::SetLong(long long n) {
verify( _element.type() == NumberLong );
*getDur().writing( reinterpret_cast< long long * >(value()) ) = n;
}
void BSONElementManipulator::SetInt(int n) {
verify( _element.type() == NumberInt );
getDur().writingInt( *reinterpret_cast< int * >( value() ) ) = n;
}

void inProgCmd( Message &m, DbResponse &dbresponse ) {
DbMessage d(m);
QueryMessage q(d);
Expand Down
82 changes: 0 additions & 82 deletions src/mongo/db/jsobjmanipulator.h

This file was deleted.

1 change: 0 additions & 1 deletion src/mongo/db/mongod.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4474,7 +4474,6 @@ cscript //Nologo "$(ProjectDir)..\shell\createCPPfromJavaScriptFiles.js" "$(Proj
<ClInclude Include="index_update.h" />
<ClInclude Include="initialize_server_global_state.h" />
<ClInclude Include="intervalbtreecursor.h" />
<ClInclude Include="jsobjmanipulator.h" />
<ClInclude Include="key.h" />
<ClInclude Include="keypattern.h" />
<ClInclude Include="kill_current_op.h" />
Expand Down
3 changes: 0 additions & 3 deletions src/mongo/db/mongod.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -3896,9 +3896,6 @@
<ClInclude Include="filever.h">
<Filter>db\Header Files\e to n</Filter>
</ClInclude>
<ClInclude Include="jsobjmanipulator.h">
<Filter>db\Header Files\e to n</Filter>
</ClInclude>
<ClInclude Include="key.h">
<Filter>db\Header Files\e to n</Filter>
</ClInclude>
Expand Down
1 change: 0 additions & 1 deletion src/mongo/dbtests/test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,6 @@ cscript //Nologo "$(ProjectDir)..\shell\createCPPfromJavaScriptFiles.js" "$(Proj
<ClInclude Include="..\db\interrupt_status.h" />
<ClInclude Include="..\db\interrupt_status_mongod.h" />
<ClInclude Include="..\db\intervalbtreecursor.h" />
<ClInclude Include="..\db\jsobjmanipulator.h" />
<ClInclude Include="..\db\key.h" />
<ClInclude Include="..\db\keypattern.h" />
<ClInclude Include="..\db\kill_current_op.h" />
Expand Down
6 changes: 0 additions & 6 deletions src/mongo/dbtests/test.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,6 @@
<ClInclude Include="..\db\jsobj.h">
<Filter>db\Header Files\e to n</Filter>
</ClInclude>
<ClInclude Include="..\db\jsobjmanipulator.h">
<Filter>db\Header Files\e to n</Filter>
</ClInclude>
<ClInclude Include="..\db\json.h">
<Filter>db\Header Files\e to n</Filter>
</ClInclude>
Expand Down Expand Up @@ -520,9 +517,6 @@
<ClInclude Include="..\db\ops\update.h">
<Filter>db\ops</Filter>
</ClInclude>
<ClInclude Include="..\db\jsobjmanipulator.h">
<Filter>db\Header Files\e to n</Filter>
</ClInclude>
<ClInclude Include="..\db\mongomutex.h">
<Filter>db\Header Files\e to n</Filter>
</ClInclude>
Expand Down
3 changes: 1 addition & 2 deletions src/mongo/shell/mongo.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,6 @@ cscript //Nologo "$(ProjectDir)..\shell\createCPPfromJavaScriptFiles.js" "$(Proj
<ClInclude Include="..\db\index.h" />
<ClInclude Include="..\db\instance.h" />
<ClInclude Include="..\db\jsobj.h" />
<ClInclude Include="..\db\jsobjmanipulator.h" />
<ClInclude Include="..\db\json.h" />
<ClInclude Include="..\db\key.h" />
<ClInclude Include="..\db\lasterror.h" />
Expand Down Expand Up @@ -2108,4 +2107,4 @@ cscript //Nologo "$(ProjectDir)..\shell\createCPPfromJavaScriptFiles.js" "$(Proj
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
5 changes: 1 addition & 4 deletions src/mongo/shell/mongo.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1468,9 +1468,6 @@
<ClInclude Include="..\db\jsobj.h">
<Filter>db\Header Files</Filter>
</ClInclude>
<ClInclude Include="..\db\jsobjmanipulator.h">
<Filter>db\Header Files</Filter>
</ClInclude>
<ClInclude Include="..\db\json.h">
<Filter>db\Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -2620,4 +2617,4 @@
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
</Project>
8 changes: 5 additions & 3 deletions src/mongo/tools/stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "mongo/base/init.h"
#include "mongo/client/dbclientcursor.h"
#include "mongo/client/sasl_client_authenticate.h"
#include "mongo/db/jsobjmanipulator.h"
#include "mongo/db/json.h"
#include "mongo/s/type_shard.h"
#include "mongo/tools/stat_util.h"
Expand Down Expand Up @@ -201,8 +200,11 @@ namespace mongo {
if ( e.isABSONObj() ) {
BSONObj x = e.Obj();
if ( x["width"].numberInt() < *maxWidth ) {
BSONElementManipulator manip( x["width"] );
manip.setNumber( *maxWidth );
// TODO somthing less horrible.
BSONElement width = x["width"];
invariant(width.type() == NumberInt);
char* nonConstPtr = const_cast<char*>(width.value());
*reinterpret_cast<int*>(nonConstPtr) = *maxWidth;
}
else {
*maxWidth = x["width"].numberInt();
Expand Down

0 comments on commit 1f9286c

Please sign in to comment.