flow_graph_gc_node.go 1.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
package querynode

import (
	"log"
)

type gcNode struct {
	BaseNode
	replica collectionReplica
}

func (gcNode *gcNode) Name() string {
	return "gcNode"
}

func (gcNode *gcNode) Operate(in []*Msg) []*Msg {
	//fmt.Println("Do gcNode operation")

	if len(in) != 1 {
		log.Println("Invalid operate message input in gcNode, input length = ", len(in))
		// TODO: add error handling
	}

	gcMsg, ok := (*in[0]).(*gcMsg)
	if !ok {
		log.Println("type assertion failed for gcMsg")
		// TODO: add error handling
	}

	// drop collections
	for _, collectionID := range gcMsg.gcRecord.collections {
		err := gcNode.replica.removeCollection(collectionID)
		if err != nil {
			log.Println(err)
		}
	}

	// drop partitions
	for _, partition := range gcMsg.gcRecord.partitions {
		err := gcNode.replica.removePartition(partition.collectionID, partition.partitionTag)
		if err != nil {
			log.Println(err)
		}
	}

	return nil
}

func newGCNode(replica collectionReplica) *gcNode {
	maxQueueLength := Params.FlowGraphMaxQueueLength
	maxParallelism := Params.FlowGraphMaxParallelism

	baseNode := BaseNode{}
	baseNode.SetMaxQueueLength(maxQueueLength)
	baseNode.SetMaxParallelism(maxParallelism)

	return &gcNode{
		BaseNode: baseNode,
		replica:  replica,
	}
}