Revision eb29e340 som/TopologyManager/tman.c

View differences:

som/TopologyManager/tman.c
177 177
	struct peer_cache *new = NULL, *temp;
178 178
	int source = 4; // init with value > 1, needed in bootstrap/restart phase...
179 179

  
180
	if (len) {
180
	if (len && active >= 0) {
181 181
		const struct topo_header *h = (const struct topo_header *)buff;
182 182
		struct peer_cache *remote_cache;
183 183

  
......
196 196
			return 1;
197 197
		}
198 198

  
199
		if (h->type == TMAN_QUERY && active >= 0) {
199
		if (h->type == TMAN_QUERY) {
200 200
			new = cache_rank(local_cache, tmanRankFunct, nodeid(remote_cache, 0), get_metadata(remote_cache, &msize));
201 201
			if (new) {
202 202
				tman_reply(remote_cache, new);
......
207 207
		}
208 208

  
209 209
		if (restart_peer && nodeid_equal(restart_peer, nodeid(remote_cache,0))) { // restart phase : receiving new cache from chosen alive peer...
210
			cache_size = TMAN_INIT_PEERS;
211 210
			new = cache_rank(remote_cache,tmanRankFunct,NULL,mymeta);
212 211
			if (new) {
212
				cache_size = TMAN_INIT_PEERS;
213
				cache_resize(new,cache_size);
213 214
				countdown = idle_time*2;
215
				fprintf(stderr,"RESTARTING TMAN!!!\n");
214 216
			}
215 217
			nodeid_free(restart_peer);
216 218
			restart_peer = NULL;
217 219
		}
218 220
		else {	// normal phase
219
		cache_size = ((current_size/2)*3) > cache_size ? current_size*2 : cache_size;
220
			temp = cache_rank(remote_cache,tmanRankFunct,NULL,mymeta);
221
			temp = cache_union(local_cache,remote_cache,&s);
221 222
			if (temp) {
222
				new = merge_caches_ranked(local_cache, temp, cache_size, &source, tmanRankFunct, mymeta);
223
				new = cache_rank(temp,tmanRankFunct,NULL,mymeta);
224
				cache_size = ((s/2)*2.5) > cache_size ? ((s/2)*2.5) : cache_size;
225
				cache_resize(new,cache_size);
223 226
				cache_free(temp);
224 227
			}
225 228
		}
......
266 269
				cache_free(new);
267 270
			}
268 271
		if (active < 0) { // bootstrap
272
			fprintf(stderr,"BOOTSTRAPPING TMAN!!!\n");
273
			cache_free(local_cache);
269 274
			local_cache = ncache;
270 275
			current_size = size;
271 276
			cache_size = nsize;

Also available in: Unified diff