applys effects encoded in buffer
| 506 | |
| 507 | // applys effects encoded in buffer |
| 508 | void Effects_Apply |
| 509 | ( |
| 510 | GraphContext *gc, // graph to operate on |
| 511 | const char *effects_buff, // encoded effects |
| 512 | size_t l // size of buffer |
| 513 | ) { |
| 514 | // validations |
| 515 | ASSERT(l > 0); // buffer can't be empty |
| 516 | ASSERT(effects_buff != NULL); // buffer can't be NULL |
| 517 | |
| 518 | // read buffer in a stream fashion |
| 519 | FILE *stream = fmemopen((void*)effects_buff, l, "r"); |
| 520 | |
| 521 | // validate effects version |
| 522 | if(ValidateVersion(stream) == false) { |
| 523 | // replica/primary out of sync |
| 524 | exit(1); |
| 525 | } |
| 526 | |
| 527 | // lock graph for writing |
| 528 | Graph *g = GraphContext_GetGraph(gc); |
| 529 | Graph_AcquireWriteLock(g); |
| 530 | |
| 531 | // update graph sync policy |
| 532 | MATRIX_POLICY policy = Graph_SetMatrixPolicy(g, SYNC_POLICY_RESIZE); |
| 533 | |
| 534 | // as long as there's data in stream |
| 535 | while(ftell(stream) < l) { |
| 536 | // read effect type |
| 537 | EffectType t = ReadEffectType(stream); |
| 538 | switch(t) { |
| 539 | case EFFECT_DELETE_NODE: |
| 540 | ApplyDeleteNode(stream, gc); |
| 541 | break; |
| 542 | case EFFECT_DELETE_EDGE: |
| 543 | ApplyDeleteEdge(stream, gc); |
| 544 | break; |
| 545 | case EFFECT_UPDATE_NODE: |
| 546 | ApplyUpdateNode(stream, gc); |
| 547 | break; |
| 548 | case EFFECT_UPDATE_EDGE: |
| 549 | ApplyUpdateEdge(stream, gc); |
| 550 | break; |
| 551 | case EFFECT_CREATE_NODE: |
| 552 | ApplyCreateNode(stream, gc); |
| 553 | break; |
| 554 | case EFFECT_CREATE_EDGE: |
| 555 | ApplyCreateEdge(stream, gc); |
| 556 | break; |
| 557 | case EFFECT_SET_LABELS: |
| 558 | ApplyLabels(stream, gc, true); |
| 559 | break; |
| 560 | case EFFECT_REMOVE_LABELS: |
| 561 | ApplyLabels(stream, gc, false); |
| 562 | break; |
| 563 | case EFFECT_ADD_SCHEMA: |
| 564 | ApplyAddSchema(stream, gc); |
| 565 | break; |
no test coverage detected