示例#1
0
        public static string PrintPayload(this UpdatesGrpcResponse update)
        {
            var result =
                $"ClearTable={update.ClearTable}; TableName={update.TableName}; SyncPartitionId={update.ResetPartitionKey}; DownloadRows={update.DownloadRows} ";

            if (update.DbRows == null)
            {
                return(result + "DbRows=null");
            }

            return(result + "DbRows.Length=" + update.DbRows.Count);
        }
示例#2
0
        internal static async ValueTask <IGrpcConnectionUpdateCommand> HandleNewDataAsync(
            this MyNoSqlGrpcReaderConnection connection, UpdatesGrpcResponse update)
        {
            connection.LastReceiveTime = DateTime.UtcNow;

            if (update.TableName == null)
            {
                return(SkipItUpdateResult.Instance);
            }

            if (update.ClearTable)
            {
                return(new ClearTableUpdateResult(update.TableName));
            }

            if (update.DeleteRows != null)
            {
                return(new DeleteRowsCommand(update.TableName, update.DeleteRows.PartitionKey,
                                             update.DeleteRows.RowKeys));
            }

            if (update.ResetPartitionKey != null)
            {
                var dbRows = await connection.DownloadPartitionAsync(update.TableName, update.ResetPartitionKey).ToListAsync();

                return(new ResetPartitionUpdateCommand(update.TableName, update.ResetPartitionKey, dbRows));
            }



            if (update.DownloadRows != null)
            {
                var dbRows = await connection.MyNoSqlGrpcServerReader.SyncRowsAsync(new SyncRowsGrpcRequest
                {
                    ConnectionId = connection.ConnectionId,
                    SnapshotId   = update.DownloadRows,
                    TableName    = update.TableName
                }).ToListAsync();

                return(new UpdateRowsCommand(update.TableName, dbRows));
            }


            if (update.DbRows != null)
            {
                return(new UpdateRowsCommand(update.TableName, update.DbRows));
            }

            throw new Exception("Unknown payload data. " + update.PrintPayload());
        }
        public static UpdatesGrpcResponse HandleDataToSync(this MyNoSqlReaderSession session, ISyncChangeEvent dataToSync, int maxPayloadSize)
        {
            var result = new UpdatesGrpcResponse();

            if (dataToSync is ClearTableSyncEvent clearTableSyncEvent)
            {
                result.TableName  = clearTableSyncEvent.TableName;
                result.ClearTable = true;
                return(result);
            }

            if (dataToSync is SyncPartitionEvent syncPartitionEvent)
            {
                result.TableName         = syncPartitionEvent.TableName;
                result.ResetPartitionKey = syncPartitionEvent.PartitionKey;
                return(result);
            }

            if (dataToSync is SyncRowEvent syncRowEvent)
            {
                result.TableName = syncRowEvent.TableName;

                if (syncRowEvent.PayLoadSize < maxPayloadSize)
                {
                    result.DbRows = syncRowEvent.DbRows;
                    return(result);
                }

                result.DownloadRows = session.RowsToSync.AwaitPayload(syncRowEvent.DbRows);
                return(result);
            }

            if (dataToSync is DeleteDbRowEvent deleteDbRowEvent)
            {
                result.TableName  = deleteDbRowEvent.TableName;
                result.DeleteRows =
                    new DeleteRowGrpcContract
                {
                    PartitionKey = deleteDbRowEvent.PartitionKey,
                    RowKeys      = deleteDbRowEvent.RowKeys
                };
                return(result);
            }

            return(result);
        }