~ubuntu-branches/ubuntu/saucy/uwsgi/saucy

« back to all changes in this revision

Viewing changes to cache.c

  • Committer: Package Import Robot
  • Author(s): Janos Guljas
  • Date: 2012-04-30 17:35:22 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20120430173522-qucwu1au3s9bflhb
Tags: 1.2+dfsg-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
111
111
        uint64_t slot = uwsgi.cache_hashtable[hash_key];
112
112
 
113
113
        struct uwsgi_cache_item *uci;
 
114
        uint64_t rounds = 0;
114
115
 
115
116
        //uwsgi_log("found slot %d for key %d\n", slot, hash_key);
116
117
 
117
118
        uci = &uwsgi.cache_items[slot];
118
119
 
119
120
        // first round
120
 
        if (uci->djbhash != hash) goto cycle;
 
121
        if (uci->djbhash != hash) return 0;
121
122
        if (uci->keysize != keylen) goto cycle;
122
123
        if (memcmp(uci->key, key, keylen)) goto cycle;
123
124
 
127
128
        while(uci->next) {
128
129
                slot = uci->next;
129
130
                uci = &uwsgi.cache_items[slot];
130
 
                if (uci->djbhash != hash) continue;
 
131
                rounds++;
 
132
                if (rounds > uwsgi.cache_max_items) {
 
133
                        uwsgi_log("ALARM !!! cache-loop (and potential deadlock) detected slot = %llu prev = %llu next = %llu\n", uci->next, slot, uci->prev, uci->next);       
 
134
                        // terrible case: the whole uWSGI stack can deadlock, leaving only the master alive
 
135
                        // if the master is avalable, trigger a brutal reload
 
136
                        if (uwsgi.master_process) {
 
137
                                kill(uwsgi.workers[0].pid, SIGTERM);
 
138
                        }
 
139
                        // otherwise kill the current worker (could be pretty useless...)
 
140
                        else {
 
141
                                exit(1);
 
142
                        }
 
143
                }
 
144
                if (uci->djbhash != hash) return 0;
131
145
                if (uci->keysize != keylen) continue;
132
146
                if (!memcmp(uci->key, key, keylen)) return slot;
133
147
        }
154
168
        return NULL;
155
169
}
156
170
 
157
 
int uwsgi_cache_del(char *key, uint16_t keylen) {
 
171
int uwsgi_cache_del(char *key, uint16_t keylen, uint64_t index) {
158
172
 
159
 
        uint64_t index = 0;
160
173
        struct uwsgi_cache_item *uci;
161
174
        int ret = -1;
162
175
 
163
 
        index = uwsgi_cache_get_index(key, keylen);
 
176
        if (!index)
 
177
                index = uwsgi_cache_get_index(key, keylen);
 
178
 
164
179
        if (index) {
165
180
                uci = &uwsgi.cache_items[index] ;
166
181
                uci->keysize = 0;
177
192
                if (uci->prev) {
178
193
                        uwsgi.cache_items[uci->prev].next = uci->next;  
179
194
                }
 
195
                else {
 
196
                        // set next as the new entry point (could be 0)
 
197
                        uwsgi.cache_hashtable[uci->djbhash % 0xffff] = uci->next;
 
198
                }
 
199
 
180
200
                if (uci->next) {
181
201
                        uwsgi.cache_items[uci->next].prev = uci->prev;  
182
202
                }
 
203
 
183
204
                if (!uci->prev && !uci->next) {
184
205
                        // reset hashtable entry
185
206
                        //uwsgi_log("!!! resetted hashtable entry !!!\n");
188
209
                uci->djbhash = 0;
189
210
                uci->prev = 0;
190
211
                uci->next = 0;
 
212
                uci->expires = 0;
191
213
        }
192
214
 
193
215
        return ret;
262
284
                ret = 0;
263
285
                // now put the value in the 16bit hashtable
264
286
                slot = uci->djbhash % 0xffff;
 
287
                // reset values
 
288
                uci->prev = 0;
 
289
                uci->next = 0;
265
290
 
266
291
                if (uwsgi.cache_hashtable[slot] == 0) {
267
292
                        uwsgi.cache_hashtable[slot] = index;