Пример #1
0
        private static unsafe void WritePartitionKeyRange(KeyPredicate?[] predicates,
                                                          byte appId, EntityModel model,
                                                          byte *bk, byte *ek, int *varSizes)
        {
            var   tableId = model.TableId;
            byte *tiPtr   = (byte *)&tableId;

            bk[0] = ek[0] = appId;
            bk[1] = ek[1] = tiPtr[2];
            bk[2] = ek[2] = tiPtr[1];
            bk[3] = ek[3] = tiPtr[0];
            bk[4] = ek[4] = KeyUtil.PARTCF_PART_TABLE_FLAG;

            if (predicates == null || !predicates[0].HasValue) //short path for no predicate
            {
                ek[4] = KeyUtil.PARTCF_PART_TABLE_FLAG + 1;
                return;
            }

            var bw = new EntityStoreWriter(bk, 5);
            var ew = new EntityStoreWriter(ek, 5);

            for (int i = 0; i < predicates.Length; i++)
            {
                if (!predicates[i].HasValue)
                {
                    break;                          //没有指定谓词跳出
                }
                var m       = predicates[i].Value.Value;
                var ruleArg = model.SysStoreOptions.PartitionKeys[i].RuleArgument;

                switch (predicates[i].Value.Type)
                {
                case KeyPredicateType.Equal:
                {
                    if (model.SysStoreOptions.PartitionKeys[i].Rule == PartitionKeyRule.Hash)
                    {
                        int pkValue = EntityStoreWriter.GetHashOfPK(m.BoxedValue, ruleArg);
                        bw.WriteUInt16((ushort)(m.Id | 4));
                        bw.WriteInt32(pkValue);
                        ew.WriteUInt16((ushort)(m.Id | 4));
                        ew.WriteInt32(pkValue);
                    }
                    else if (model.SysStoreOptions.PartitionKeys[i].Rule == PartitionKeyRule.RangeOfDate)
                    {
                    }
                    else
                    {
                    }
                }
                break;

                default:
                    throw new NotImplementedException();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 用于写入全部相等的分区Key
        /// </summary>
        private unsafe void WritePartitionKey(byte appId, EntityModel model, byte *key, int *varSizes)
        {
            var   tableId = model.TableId;
            byte *tiPtr   = (byte *)&tableId;

            key[0] = appId;
            key[1] = tiPtr[2];
            key[2] = tiPtr[1];
            key[3] = tiPtr[0];
            key[4] = KeyUtil.PARTCF_PART_TABLE_FLAG;

            var w = new EntityStoreWriter(key, 5);

            for (int i = 0; i < predicates.Length; i++)
            {
                Debug.Assert(predicates[i].Value.Type == KeyPredicateType.Equal);

                var m       = predicates[i].Value.Value;
                var ruleArg = model.SysStoreOptions.PartitionKeys[i].RuleArgument;

                if (model.SysStoreOptions.PartitionKeys[i].Rule == PartitionKeyRule.Hash)
                {
                    int pkValue = EntityStoreWriter.GetHashOfPK(m.BoxedValue, ruleArg);
                    w.WriteUInt16((ushort)(m.Id | 4)); //不用写排序标记
                    w.WriteInt32(pkValue);
                }
                else if (model.SysStoreOptions.PartitionKeys[i].Rule == PartitionKeyRule.RangeOfDate)
                {
                    int    pkValue = EntityStoreWriter.GetRangeOfPK(m.DateTimeValue, (DatePeriod)ruleArg);
                    ushort mid     = m.Id;
                    if (model.SysStoreOptions.PartitionKeys[i].OrderByDesc)
                    {
                        mid |= 1 << IdUtil.MEMBERID_ORDER_OFFSET;
                    }
                    w.WriteUInt16((ushort)(mid | 4)); //写入排序标记
                    w.WriteInt32(pkValue);
                }
                else
                {
                    w.WriteMember(ref m, varSizes + i, true, model.SysStoreOptions.PartitionKeys[i].OrderByDesc);
                }
            }
        }