Revision eb29e340

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;
som/TopologyManager/topocache.c
423 423

  
424 424
}
425 425
  
426

  
427

  
428
struct peer_cache *merge_caches_ranked(struct peer_cache *c1, struct peer_cache *c2, int newsize, int *source, ranking_function rank, void *mymetadata)
426
struct peer_cache *merge_caches(struct peer_cache *c1, struct peer_cache *c2, int newsize, int *source)
429 427
{
430 428
  int n1, n2;
431 429
  struct peer_cache *new_cache;
......
465 463
      }
466 464
      n1++;
467 465
    } else {
468
      int nowFirst;
469

  
470
      nowFirst = 0;
471
      if (rank) {
472
        nowFirst = rank(mymetadata, c1->metadata + n1 * c1->metadata_size,
473
                        c2->metadata + n2 * c2->metadata_size);
474
      }
475
      if (nowFirst == 0) {
476
        nowFirst = c2->entries[n2].timestamp > c1->entries[n1].timestamp ? 1 : 2;
477
      }
478
      if (nowFirst == 1) {
466
      if (c2->entries[n2].timestamp > c1->entries[n1].timestamp) {
479 467
        if (in_cache(new_cache, &c1->entries[n1]) < 0) {
480 468
          if (new_cache->metadata_size) {
481 469
            memcpy(meta, c1->metadata + n1 * c1->metadata_size, c1->metadata_size);
......
503 491

  
504 492
  return new_cache;
505 493
}
506

  
507
struct peer_cache *merge_caches(struct peer_cache *c1, struct peer_cache *c2, int newsize, int *source)
508
{
509
  return merge_caches_ranked(c1, c2, newsize, source, NULL, NULL);
510
}
som/TopologyManager/topocache.h
20 20
int cache_header_dump(uint8_t *b, const struct peer_cache *c);
21 21
int entry_dump(uint8_t *b, struct peer_cache *e, int i);
22 22

  
23
struct peer_cache *merge_caches_ranked(struct peer_cache *c1, struct peer_cache *c2, int newsize, int *source, ranking_function rank, void *mymeta);
24 23
struct peer_cache *merge_caches(struct peer_cache *c1, struct peer_cache *c2, int newsize, int *source);
25 24
struct peer_cache *cache_rank (const struct peer_cache *c, ranking_function rank, const struct nodeID *target, const void *target_meta);
26 25
struct peer_cache *cache_union(struct peer_cache *c1, struct peer_cache *c2, int *size);

Also available in: Unified diff