Exemplo n.º 1
0
        public void BulkCall(params BulkOperation[] operations)
        {
            JArray opArray = new JArray();
            Dictionary <string, string> knownEtags = new Dictionary <string, string>();

            // Prepare opArray
            foreach (BulkOperation operation in operations)
            {
                opArray.Add(operation.OperationJObject);
                foreach (KeyValuePair <string, string> pair in operation.KnownEtags)
                {
                    string docId = pair.Key;
                    string etag  = pair.Value;
#if DEBUG
                    if (knownEtags.ContainsKey(docId))
                    {
                        Debug.Assert(knownEtags[docId] == etag);
                    }
#endif
                    knownEtags[docId] = etag;
                }
            }

            // Do the call!
            string       responseBody = this.Connection.ExecuteBulkOperation(opArray, knownEtags);
            BulkResponse response     = JsonConvert.DeserializeObject <BulkResponse>(responseBody);
            if (response.Status != BulkStatus.Success)
            {
                throw new Exception($"BulkCall failed: {response.Message}");
            }

            // Invoke the callbacks
            for (int index = 0; index < operations.Length; ++index)
            {
                JToken content = response.Content[index];
                if ((content as JValue)?.Type == JTokenType.Null)
                {
                    operations[index].Callback(response, null);
                }
                else
                {
                    Debug.Assert(content is JObject);
                    operations[index].Callback(response, (JObject)content);
                }
            }


            //
            // Update etags in cache
            // NOTE: This MUST be done after all callbacks are invoked.
            //       That is, to ensure the etags are not changed in the callbacks
            //
            foreach (KeyValuePair <string, string> pair in response.Etags)
            {
                string docId = pair.Key;
                string etag  = pair.Value;
                if (etag != null)
                {
                    this.Connection.VertexCache.UpdateCurrentEtag(docId, etag);
                }
                else
                {
                    // If (etag == null), it means the etag is unknown
                    // Or this document is deleted by operation
                    this.Connection.VertexCache.TryRemoveEtag(docId);
                }
            }
        }
Exemplo n.º 2
0
 public override void Callback(BulkResponse response, JObject content)
 {
     this._vertexObject[KW_DOC_ETAG] = response.Etags[(string)this._vertexObject[KW_DOC_ID]];
     Debug.Assert(this._vertexObject[KW_DOC_ETAG] != null);
 }
Exemplo n.º 3
0
        public override void Callback(BulkResponse response, JObject content)
        {
            Debug.Assert((bool)content["found"] == true);

            this.OppoSideVertexId = (string)content["oppoSideVId"];
        }
Exemplo n.º 4
0
 public override void Callback(BulkResponse response, JObject content)
 {
     Debug.Assert((bool)content["found"] == true);
 }
Exemplo n.º 5
0
 public abstract void Callback(BulkResponse response, JObject content);
Exemplo n.º 6
0
 public override void Callback(BulkResponse response, JObject content)
 {
     this.Found = (bool)content["found"];
 }
Exemplo n.º 7
0
        public override void Callback(BulkResponse response, JObject content)
        {
            this.FirstSpillEdgeDocId = (string)content["firstSpillEdgeDocId"];
            this.NewEdgeDocId        = (string)content["newEdgeDocId"];


            //
            // Actually, there might be at most three documents whose etag are upserted
            //  - The vertex document: when nonspilled->nonspilled or nonspilled->spilled or spilled-but-create-new-edge-document
            //  - The edge document (firstSpillEdgeDocId): when nonspilled->spilled, the existing edges are spilled into this document
            //  - The edge document (newEdgeDocId): when spilled, the new edge is always stored here
            //

            //
            // Update vertex JObject's etag (if necessary)
            //
            if (response.Etags.ContainsKey(this._vertexId))
            {
                // The vertex is updated, either because it is changed from non-spilled to spilled, or
                // because its latest spilled edge document is updated
                Debug.Assert(response.Etags[this._vertexId] != null);
            }

            //
            // Update vertex edgeContainer's content (if necessary)
            //
            string latestEdgeDocId = this._isReverse
                ? this._thisVertexField.LatestInEdgeDocumentId
                : this._thisVertexField.LatestOutEdgeDocumentId;

            if (latestEdgeDocId != null)
            {
                // The edges are originally spilled (now it is still spilled)
                Debug.Assert(this.FirstSpillEdgeDocId == null);

                if (this.NewEdgeDocId == latestEdgeDocId)
                {
                    // Now the newly added edge is added to the latest edge document (not too large)
                    // Do nothing
                    // The vertex object should not be updated (etag not changed)
                    Debug.Assert(response.Etags[this._vertexId] == this.Connection.VertexCache.GetCurrentEtag(this._vertexId));
                }
                else
                {
                    // Now the newly added edge is stored in a new edge document
                    // The original latest edge document is too small to store the new edge
                    // Update the vertex object's latest edge document id
                    Debug.Assert(response.Etags.ContainsKey(this._vertexId));
                    Debug.Assert(response.Etags[this._vertexId] != this.Connection.VertexCache.GetCurrentEtag(this._vertexId));

                    if (this._isReverse)
                    {
                        this._thisVertexField.LatestInEdgeDocumentId = this.NewEdgeDocId;
                    }
                    else
                    {
                        this._thisVertexField.LatestOutEdgeDocumentId = this.NewEdgeDocId;
                    }
                }
            }
            else
            {
                // The vertex's edges are originally not spilled
                Debug.Assert(response.Etags.ContainsKey(this._vertexId));

                if (this.FirstSpillEdgeDocId != null)
                {
                    // Now the vertex is changed from not-spilled to spilled
                    Debug.Assert(this.NewEdgeDocId != null);
                    if (this._isReverse)
                    {
                        this._thisVertexField.LatestInEdgeDocumentId = this.NewEdgeDocId;
                    }
                    else
                    {
                        this._thisVertexField.LatestOutEdgeDocumentId = this.NewEdgeDocId;
                    }
                }
                else
                {
                    // Now the vertex is still not spilled
                    Debug.Assert(this.NewEdgeDocId == null);
                }
            }
        }