3
/* Copyright 2009 10gen Inc.
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
20
#include <boost/thread/tss.hpp>
22
#define assert xassert
31
enum UpdatedExistingType { NotUpdate, True, False } updatedExisting;
32
/* todo: nObjects should be 64 bit */
38
void raiseError(int _code , const char *_msg) {
43
void recordUpdate( bool _updatedExisting, int nChanged ) {
46
updatedExisting = _updatedExisting ? True : False;
48
void recordDelete( int nDeleted ) {
53
overridenById = false;
56
void reset( bool _valid = false ) {
59
updatedExisting = NotUpdate;
65
void appendSelf( BSONObjBuilder &b );
66
static LastError noError;
69
extern class LastErrorHolder {
71
LastErrorHolder() : _id( 0 ) {}
73
LastError * get( bool create = false );
75
LastError * _get( bool create = false ); // may return a disabled LastError
77
void reset( LastError * le );
80
* id of 0 means should use thread local management
85
void remove( int id );
88
/** when db receives a message/request, call this */
89
void startRequest( Message& m , LastError * connectionOwned );
90
void startRequest( Message& m );
92
// used to disable lastError reporting while processing a killCursors message
93
// disable causes get() to return 0.
94
LastError *disableForCommand(); // only call once per command invocation!
96
ThreadLocalValue<int> _id;
97
boost::thread_specific_ptr<LastError> _tl;
103
static boost::mutex _idsmutex;
104
map<int,Status> _ids;
107
inline void raiseError(int code , const char *msg) {
108
LastError *le = lastError.get();
110
DEV log() << "warning: lastError==0 can't report:" << msg << '\n';
111
} else if ( le->disabled ) {
112
log() << "lastError disabled, can't report: " << msg << endl;
114
le->raiseError(code, msg);
118
inline void recordUpdate( bool updatedExisting, int nChanged ) {
119
LastError *le = lastError.get();
121
le->recordUpdate( updatedExisting, nChanged );
124
inline void recordDelete( int nDeleted ) {
125
LastError *le = lastError.get();
127
le->recordDelete( nDeleted );