Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
cdy816
Mars
提交
547920cb
Mars
项目概览
cdy816
/
Mars
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
547920cb
编写于
10月 16, 2020
作者:
cdy816
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
BUG 修改
上级
50cabe22
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
262 addition
and
416 deletion
+262
-416
Common/Cdy.Tag/His/CompressUnitManager2.cs
Common/Cdy.Tag/His/CompressUnitManager2.cs
+10
-0
RunTime/DBHisData/HisQuery/TimeFile/DataFileInfo.cs
RunTime/DBHisData/HisQuery/TimeFile/DataFileInfo.cs
+33
-71
RunTime/DBRuntime/His/Compress/CompressEnginer2.cs
RunTime/DBRuntime/His/Compress/CompressEnginer2.cs
+1
-0
RunTime/DBRuntime/His/Compress/CompressMemory2.cs
RunTime/DBRuntime/His/Compress/CompressMemory2.cs
+20
-7
RunTime/DBRuntime/His/HisEnginer2.cs
RunTime/DBRuntime/His/HisEnginer2.cs
+25
-184
RunTime/DBRuntime/His/SeriseEnginer2.cs
RunTime/DBRuntime/His/SeriseEnginer2.cs
+173
-154
未找到文件。
Common/Cdy.Tag/His/CompressUnitManager2.cs
浏览文件 @
547920cb
...
...
@@ -49,6 +49,16 @@ namespace Cdy.Tag
#
endregion
...
Constructor
...
#
region
...
Properties
...
/// <summary>
///
/// </summary>
public
Dictionary
<
int
,
CompressUnitbase2
>
CompressUnit
{
get
{
return
mCompressUnit
;
}
}
#
endregion
...
Properties
...
...
...
RunTime/DBHisData/HisQuery/TimeFile/DataFileInfo.cs
浏览文件 @
547920cb
...
...
@@ -170,7 +170,8 @@ namespace Cdy.Tag
{
return
;
}
try
{
do
{
//读取数据区时间
...
...
@@ -207,50 +208,11 @@ namespace Cdy.Tag
{
mLastTime
=
tmp
;
}
}
catch
{
//if (mLastProcessOffset == -1)
//{
//}
//else
//{
// offset = mLastProcessOffset;
// //读取数据区时间
// time = ss.ReadDateTime(offset + 16);
// long oset = offset;
// //读取下个区域位置
// offset = ss.ReadLong(offset + 8);
// if (offset != 0)
// {
// var dt2 = ss.ReadDateTime(offset + 16);
// if (mTimeOffsets.ContainsKey(time))
// {
// mTimeOffsets[time] = new Tuple<TimeSpan, long, DateTime>(dt2 - time, oset, dt2);
// }
// else
// {
// mTimeOffsets.Add(time, new Tuple<TimeSpan, long, DateTime>(dt2 - time, oset, dt2));
// }
// tmp = dt2;
// }
// else
// {
// var tspan = StartTime + Duration - time;
// if (tspan.TotalMilliseconds > 0)
// {
// if (mTimeOffsets.ContainsKey(time))
// {
// mTimeOffsets[time] = new Tuple<TimeSpan, long, DateTime>(tspan, oset, time + tspan);
// }
// else
// {
// mTimeOffsets.Add(time, new Tuple<TimeSpan, long, DateTime>(tspan, oset, time + tspan));
// }
// }
// tmp = time + tspan;
// }
//}
}
mInited
=
true
;
}
...
...
RunTime/DBRuntime/His/Compress/CompressEnginer2.cs
浏览文件 @
547920cb
...
...
@@ -304,6 +304,7 @@ namespace Cdy.Tag
sm
.
Clear
();
sm
.
MakeMemoryNoBusy
();
System
.
Threading
.
Tasks
.
Parallel
.
ForEach
(
mTargetMemorys
.
Where
(
e
=>
e
.
Value
.
HasManualCompressItems
),
(
mm
)
=>
{
ThreadHelper
.
AssignToCPU
(
CPUAssignHelper
.
Helper
.
CPUArray2
);
...
...
RunTime/DBRuntime/His/Compress/CompressMemory2.cs
浏览文件 @
547920cb
...
...
@@ -207,16 +207,29 @@ namespace Cdy.Tag
{
mTagIds
.
Clear
();
long
lsize
=
0
;
//var tagserver = ServiceLocator.Locator.Resolve<IHisEngine2>();
//var tags = tagserver.ListAllTags().Where(e => e.Id >= Id * TagCountPerMemory && e.Id < (Id + 1) * TagCountPerMemory).OrderBy(e => e.Id);
foreach
(
var
vv
in
CompressUnitManager2
.
Manager
.
CompressUnit
)
{
mCompressCach
.
Add
(
vv
.
Key
,
vv
.
Value
.
Clone
());
}
//foreach(var vv in tags)
//{
// var cpt = vv.CompressType;
// if (!mCompressCach.ContainsKey(cpt))
// {
// mCompressCach.Add(cpt, CompressUnitManager2.Manager.GetCompressQuick(cpt).Clone());
// }
//}
foreach
(
var
vv
in
sourceM
.
TagAddress
.
Where
(
e
=>
e
.
Key
>=
Id
*
TagCountPerMemory
&&
e
.
Key
<
(
Id
+
1
)
*
TagCountPerMemory
))
{
mTagIds
.
Add
(
vv
.
Key
);
dtmp
.
Add
(
vv
.
Key
,
0
);
var
cpt
=
mHisTagService
.
GetHisTag
(
vv
.
Key
).
CompressType
;
if
(!
mCompressCach
.
ContainsKey
(
cpt
))
{
mCompressCach
.
Add
(
cpt
,
CompressUnitManager2
.
Manager
.
GetCompressQuick
(
cpt
).
Clone
());
}
if
(
vv
.
Value
!=
null
)
lsize
+=
vv
.
Value
.
Length
;
}
...
...
RunTime/DBRuntime/His/HisEnginer2.cs
浏览文件 @
547920cb
...
...
@@ -848,14 +848,14 @@ namespace Cdy.Tag
cachHeadSize
+=
css
;
}
else
{
mMergeMemory1
.
AddTagAddress
(
vv
.
Value
.
Id
,
null
);
mMergeMemory2
.
AddTagAddress
(
vv
.
Value
.
Id
,
null
);
//
else
//
{
//
mMergeMemory1.AddTagAddress(vv.Value.Id, null);
//
mMergeMemory2.AddTagAddress(vv.Value.Id, null);
mCachMemory1
.
AddTagAddress
(
vv
.
Value
.
Id
,
null
);
mCachMemory2
.
AddTagAddress
(
vv
.
Value
.
Id
,
null
);
}
//
mCachMemory1.AddTagAddress(vv.Value.Id, null);
//
mCachMemory2.AddTagAddress(vv.Value.Id, null);
//
}
}
...
...
@@ -1054,14 +1054,18 @@ namespace Cdy.Tag
Stopwatch
sw
=
new
Stopwatch
();
sw
.
Start
();
foreach
(
var
tag
in
mHisTags
)
//foreach (var tag in mHisTags)
foreach
(
var
vv
in
mcc
.
TagAddress
)
{
var
taddrs
=
mCurrentMergeMemory
.
TagAddress
[
tag
.
Value
.
Id
];
var
tag
=
mHisTags
[
vv
.
Key
];
var
taddrs
=
mCurrentMergeMemory
.
TagAddress
[
tag
.
Id
];
var
saddrs
=
mcc
.
TagAddress
[
tag
.
Value
.
Id
];
//var saddrs = mcc.TagAddress[tag.Value.Id];
var
saddrs
=
vv
.
Value
;
//
if
(
taddrs
==
null
||
saddrs
==
null
)
continue
;
//
if (taddrs == null || saddrs == null) continue;
//拷贝时间
var
dlen
=
saddrs
.
ValueAddress
;
...
...
@@ -1071,12 +1075,12 @@ namespace Cdy.Tag
//拷贝数值
dlen
=
saddrs
.
QualityAddress
-
saddrs
.
ValueAddress
;
vtimeaddr
=
taddrs
.
ValueAddress
+
dlen
*
count
+
tag
.
Value
.
SizeOfValue
;
vtimeaddr
=
taddrs
.
ValueAddress
+
dlen
*
count
+
tag
.
SizeOfValue
;
saddrs
.
CopyTo
(
taddrs
,
saddrs
.
ValueAddress
,
vtimeaddr
,
dlen
);
//拷贝质量戳
dlen
=
tag
.
Value
.
DataSize
-
saddrs
.
QualityAddress
;
dlen
=
tag
.
DataSize
-
saddrs
.
QualityAddress
;
vtimeaddr
=
taddrs
.
QualityAddress
+
dlen
*
count
+
1
;
saddrs
.
CopyTo
(
taddrs
,
saddrs
.
QualityAddress
,
vtimeaddr
,
dlen
);
...
...
@@ -1166,6 +1170,7 @@ namespace Cdy.Tag
sw
.
Start
();
foreach
(
var
vv
in
mHisTags
)
{
if
(
vv
.
Value
.
Type
!=
RecordType
.
Driver
)
vv
.
Value
.
Snape
();
}
sw
.
Stop
();
...
...
@@ -1314,9 +1319,12 @@ namespace Cdy.Tag
mNeedSnapAllTag
=
true
;
mForceSubmiteToCompress
=
true
;
mIsClosed
=
true
;
SaveManualCachData
();
SubmiteMemory
(
DateTime
.
Now
);
while
(!
mMegerProcessIsClosed
)
Thread
.
Sleep
(
1
);
SaveManualCachData
();
}
/// <summary>
...
...
@@ -1619,7 +1627,7 @@ namespace Cdy.Tag
isNeedSubmite
=
true
;
}
}
if
(
isNeedSubmite
)
if
(
isNeedSubmite
)
ServiceLocator
.
Locator
.
Resolve
<
IDataCompress2
>().
SubmitManualToCompress
();
}
...
...
@@ -1641,173 +1649,6 @@ namespace Cdy.Tag
private
bool
ManualRecordHisValues
(
long
id
,
Cdy
.
Tag
.
TagValue
value
,
int
timeUnit
=
100
)
{
return
ManualRecordHisValues
(
id
,
value
.
Time
,
value
.
Value
,
value
.
Quality
,
timeUnit
);
//if (mIsClosed) return false;
//int valueOffset, qulityOffset = 0;
//DateTime mLastTime = DateTime.MinValue;
//SortedDictionary<DateTime, ManualHisDataMemoryBlock> datacach;
//if (mHisTags.ContainsKey(id) && mHisTags[id].Type == RecordType.Manual)
//{
// if (mManualHisDataCach.ContainsKey(id))
// {
// datacach = mManualHisDataCach[id];
// }
// else
// {
// datacach = new SortedDictionary<DateTime, ManualHisDataMemoryBlock>();
// mManualHisDataCach.Add(id, datacach);
// }
// var tag = mHisTags[id];
// ManualHisDataMemoryBlock hb = null;
// var vdata = value.Time.Date;
// var mms = (int)(value.Time.Subtract(vdata).TotalSeconds / MergeMemoryTime);
// var time = vdata.AddSeconds(mms * MergeMemoryTime);
// if (datacach.ContainsKey(time))
// {
// hb = datacach[time];
// }
// else
// {
// var css = CalCachDatablockSize(tag.TagType, 0, MergeMemoryTime * 1000 / timeUnit, out valueOffset, out qulityOffset);
// hb = ManualHisDataMemoryBlockPool.Pool.Get(css);
// hb.Time = time;
// hb.MaxCount = MergeMemoryTime * 1000 / timeUnit;
// hb.TimeUnit = timeUnit;
// hb.TimeLen = 4;
// hb.TimerAddress = 0;
// hb.ValueAddress = valueOffset;
// hb.QualityAddress = qulityOffset;
// hb.Id = (int)id;
// hb.CurrentCount = 0;
// datacach.Add(time, hb);
// }
// mLastTime = time;
// if (hb.CurrentCount < hb.MaxCount && value.Time > hb.EndTime)
// {
// hb.Lock();
// var vtime = (int)((value.Time - hb.Time).TotalMilliseconds / timeUnit);
// //写入时间戳
// hb.WriteInt(hb.TimerAddress + hb.CurrentCount * 4, vtime);
// switch (tag.TagType)
// {
// case TagType.Bool:
// hb.WriteByteDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, Convert.ToByte(Convert.ToBoolean(value.Value)));
// break;
// case TagType.Byte:
// hb.WriteByteDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, Convert.ToByte(value.Value));
// break;
// case TagType.Short:
// hb.WriteShortDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, Convert.ToInt16(value.Value));
// break;
// case TagType.UShort:
// hb.WriteUShortDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, Convert.ToUInt16(value.Value));
// break;
// case TagType.Int:
// hb.WriteIntDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, Convert.ToInt32(value.Value));
// break;
// case TagType.UInt:
// hb.WriteUIntDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, Convert.ToUInt32(value.Value));
// break;
// case TagType.Long:
// hb.WriteLongDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, Convert.ToInt64(value.Value));
// break;
// case TagType.ULong:
// hb.WriteULongDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, Convert.ToUInt64(value.Value));
// break;
// case TagType.Float:
// hb.WriteFloatDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, Convert.ToSingle(value.Value));
// break;
// case TagType.Double:
// hb.WriteDoubleDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, Convert.ToDouble(value.Value));
// break;
// case TagType.String:
// hb.WriteStringDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, Convert.ToString(value.Value), Encoding.Unicode);
// break;
// case TagType.DateTime:
// hb.WriteDatetime(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, Convert.ToDateTime(value.Value));
// break;
// case TagType.UIntPoint:
// UIntPointData data = (UIntPointData)value.Value;
// hb.WriteUIntDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, data.X);
// hb.WriteUIntDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue + 4, data.Y);
// break;
// case TagType.IntPoint:
// IntPointData idata = (IntPointData)value.Value;
// hb.WriteIntDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, idata.X);
// hb.WriteIntDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue + 4, idata.Y);
// break;
// case TagType.UIntPoint3:
// UIntPoint3Data udata3 = (UIntPoint3Data)value.Value;
// hb.WriteUIntDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, udata3.X);
// hb.WriteUIntDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue + 4, udata3.Y);
// hb.WriteUIntDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue + 8, udata3.Z);
// break;
// case TagType.IntPoint3:
// IntPoint3Data idata3 = (IntPoint3Data)value.Value;
// hb.WriteIntDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, idata3.X);
// hb.WriteIntDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue + 4, idata3.Y);
// hb.WriteIntDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue + 8, idata3.Z);
// break;
// case TagType.ULongPoint:
// ULongPointData udata = (ULongPointData)value.Value;
// hb.WriteULongDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, udata.X);
// hb.WriteULongDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue + 8, udata.Y);
// break;
// case TagType.LongPoint:
// LongPointData lidata = (LongPointData)value.Value;
// hb.WriteLongDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, lidata.X);
// hb.WriteLongDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue + 8, lidata.Y);
// break;
// case TagType.ULongPoint3:
// ULongPoint3Data ludata3 = (ULongPoint3Data)value.Value;
// hb.WriteULongDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, ludata3.X);
// hb.WriteULongDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue + 16, ludata3.Y);
// hb.WriteULongDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue + 24, ludata3.Z);
// break;
// case TagType.LongPoint3:
// LongPoint3Data lidata3 = (LongPoint3Data)value.Value;
// hb.WriteLongDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue, lidata3.X);
// hb.WriteLongDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue + 16, lidata3.Y);
// hb.WriteLongDirect(hb.ValueAddress + hb.CurrentCount * tag.SizeOfValue + 24, lidata3.Z);
// break;
// }
// hb.WriteInt(hb.QualityAddress + hb.CurrentCount, value.Quality);
// hb.EndTime = value.Time;
// hb.CurrentCount++;
// hb.Relase();
// HisDataMemoryQueryService.Service.RegistorManual(id, hb.Time, hb.EndTime, hb);
// }
// bool isNeedSubmite = false;
// foreach (var vv in datacach.ToArray())
// {
// if (vv.Key < mLastTime || vv.Value.CurrentCount >= vv.Value.MaxCount)
// {
// ServiceLocator.Locator.Resolve<IDataCompress2>().RequestManualToCompress(vv.Value);
// datacach.Remove(vv.Key);
// isNeedSubmite = true;
// }
// }
// if (isNeedSubmite)
// ServiceLocator.Locator.Resolve<IDataCompress2>().SubmitManualToCompress();
// return true;
//}
//else
//{
// return false;
//}
}
/// <summary>
...
...
RunTime/DBRuntime/His/SeriseEnginer2.cs
浏览文件 @
547920cb
...
...
@@ -262,11 +262,9 @@ namespace Cdy.Tag
if
(
id
>=
vv
.
Value
.
IdStart
&&
id
<
vv
.
Value
.
IdEnd
)
{
vv
.
Value
.
AppendManualSeriseFile
(
id
,
data
);
//mManualRequestSaveCount++;
break
;
}
}
//if (mManualRequestSaveCount > 10) RequestToSave();
}
/// <summary>
///
...
...
@@ -313,9 +311,6 @@ namespace Cdy.Tag
sw
.
Stop
();
LoggerService
.
Service
.
Info
(
"SeriseEnginer"
,
">>>>>>>>>完成执行存储>>>>>>> ElapsedMilliseconds:"
+
sw
.
ElapsedMilliseconds
,
ConsoleColor
.
Cyan
);
//#endif
if
(
mIsClosed
)
break
;
}
closedEvent
.
Set
();
}
...
...
@@ -435,9 +430,11 @@ namespace Cdy.Tag
private
List
<
int
>
mTagIdsCach
;
private
Dictionary
<
DateTime
,
Dictionary
<
int
,
long
>>
mPointerCach
=
new
Dictionary
<
DateTime
,
Dictionary
<
int
,
long
>>();
//
private Dictionary<DateTime, Dictionary<int, long>> mPointerCach = new Dictionary<DateTime, Dictionary<int, long>>();
private
Dictionary
<
string
,
Dictionary
<
int
,
IMemoryBlock
>>
mManualHisDataCach
=
new
Dictionary
<
string
,
Dictionary
<
int
,
IMemoryBlock
>>();
private
Dictionary
<
string
,
Queue
<
IMemoryBlock
>>
mManualHisDataCach
=
new
Dictionary
<
string
,
Queue
<
IMemoryBlock
>>();
private
Dictionary
<
int
,
int
>
mTagIndexCach
=
new
Dictionary
<
int
,
int
>();
private
int
mId
=
0
;
...
...
@@ -801,10 +798,10 @@ namespace Cdy.Tag
}
private
Dictionary
<
int
,
long
>
GetDataRegionHeadPoint
(
string
sfile
,
SortedDictionary
<
int
,
DateTime
>
ids
,
DateTime
time
,
out
DataFileSeriserbase
mFileReader
)
private
Dictionary
<
int
,
List
<
long
>>
GetDataRegionHeadPoint
(
string
sfile
,
SortedDictionary
<
int
,
List
<
DateTime
>
>
ids
,
DateTime
time
,
out
DataFileSeriserbase
mFileReader
)
{
Dictionary
<
int
,
long
>
re
=
new
Dictionary
<
int
,
long
>();
Dictionary
<
int
,
List
<
long
>>
re
=
new
Dictionary
<
int
,
List
<
long
>
>();
DataFileSeriserbase
dfs
;
...
...
@@ -852,15 +849,17 @@ namespace Cdy.Tag
long
regionOffset
=
0
;
foreach
(
var
vv
in
ids
)
{
foreach
(
var
vvv
in
vv
.
Value
)
{
long
ltmp
=
0
;
//计算本次更新对应的指针区域的起始地址
var
fsh
=
(
vv
.
Value
.
Hour
/
FileDuration
)
*
FileDuration
;
int
bid
=
((
vv
.
Value
.
Hour
-
fsh
)
*
60
+
time
.
Minute
)
/
BlockDuration
;
var
fsh
=
(
vvv
.
Hour
/
FileDuration
)
*
FileDuration
;
int
bid
=
((
vvv
.
Hour
-
fsh
)
*
60
+
time
.
Minute
)
/
BlockDuration
;
if
(
mLastRegionStartTime
==
DateTime
.
MaxValue
||
vv
.
Value
<
mLastRegionStartTime
||
vv
.
Value
>
mLastRegionEndTime
)
if
(
mLastRegionStartTime
==
DateTime
.
MaxValue
||
vvv
<
mLastRegionStartTime
||
vvv
>
mLastRegionEndTime
)
{
regionOffset
=
SearchDataRegionToDatetime
(
dfs
,
vv
.
Value
,
out
mLastRegionStartTime
,
out
mLastRegionEndTime
);
regionOffset
=
SearchDataRegionToDatetime
(
dfs
,
vvv
,
out
mLastRegionStartTime
,
out
mLastRegionEndTime
);
ltmp
=
regionOffset
;
}
else
...
...
@@ -874,11 +873,20 @@ namespace Cdy.Tag
return
re
;
}
var
icount
=
mTagIdsCach
.
IndexOf
(
vv
.
Key
);
//var icount = mTagIdsCach.IndexOf(vv.Key);
var
icount
=
mTagIndexCach
[
vv
.
Key
];
ltmp
+=
mDataRegionHeadSize
+
mTagCount
*
8
*
bid
+
icount
*
8
;
re
.
Add
(
vv
.
Key
,
ltmp
);
if
(
re
.
ContainsKey
(
vv
.
Key
))
{
re
[
vv
.
Key
].
Add
(
ltmp
);
}
else
{
re
.
Add
(
vv
.
Key
,
new
List
<
long
>()
{
ltmp
});
}
// re.Add(vv.Key, ltmp);
}
}
//LoggerService.Service.Debug("SeriseEnginer", "DataRegion Pointer:" + ltmp + ",mDataRegionHeadSize:" + mDataRegionHeadSize + ",BlockIndex:" + bid + " tag index:" + icount);
...
...
@@ -972,17 +980,12 @@ namespace Cdy.Tag
{
if
(
mManualHisDataCach
.
ContainsKey
(
sfile
))
{
if
(!
mManualHisDataCach
[
sfile
].
ContainsKey
(
id
))
mManualHisDataCach
[
sfile
].
Add
(
id
,
datablock
);
else
{
LoggerService
.
Service
.
Warn
(
"SeriseEnginer"
,
"数据存储出现阻塞:"
+
id
);
}
mManualHisDataCach
[
sfile
].
Enqueue
(
datablock
);
}
else
{
Dictionary
<
int
,
IMemoryBlock
>
blocks
=
new
Dictionary
<
int
,
IMemoryBlock
>();
blocks
.
Add
(
id
,
datablock
);
Queue
<
IMemoryBlock
>
blocks
=
new
Queue
<
IMemoryBlock
>();
blocks
.
Enqueue
(
datablock
);
mManualHisDataCach
.
Add
(
sfile
,
blocks
);
}
}
...
...
@@ -996,8 +999,8 @@ namespace Cdy.Tag
string
oldFile
=
string
.
Empty
;
DataFileSeriserbase
mwriter
;
Dictionary
<
int
,
long
>
mHeadAddress
=
new
Dictionary
<
int
,
long
>();
Dictionary
<
int
,
long
>
mHeadValue
=
new
Dictionary
<
int
,
long
>();
Dictionary
<
int
,
List
<
long
>>
mHeadAddress
=
new
Dictionary
<
int
,
List
<
long
>
>();
Dictionary
<
int
,
List
<
long
>>
mHeadValue
=
new
Dictionary
<
int
,
List
<
long
>
>();
while
(
mManualHisDataCach
.
Count
>
0
)
{
...
...
@@ -1007,31 +1010,40 @@ namespace Cdy.Tag
mManualHisDataCach
.
Remove
(
vv
.
Key
);
}
//
Stopwatch sw = new Stopwatch();
//
sw.Start();
Stopwatch
sw
=
new
Stopwatch
();
sw
.
Start
();
//LoggerService.Service.Info("SeriseEnginer", "SeriseFileItem" + this.Id + " 开始执行存储,数据块:" + vv.Value.Count, ConsoleColor.Cyan);
//LoggerService.Service.Info("SeriseEnginer", "SeriseFileItem" + this.Id + " 开始执行存储,数据块:" + vv.Value.Count
+" 剩余:"+mManualHisDataCach.Count
, ConsoleColor.Cyan);
SortedDictionary
<
int
,
DateTime
>
times
=
new
SortedDictionary
<
int
,
DateTime
>();
SortedDictionary
<
int
,
List
<
DateTime
>>
times
=
new
SortedDictionary
<
int
,
List
<
DateTime
>
>();
DateTime
maxTime
=
DateTime
.
MinValue
;
DateTime
mLastModifyTime
=
DateTime
.
MinValue
;
foreach
(
var
vvv
in
vv
.
Value
)
{
DateTime
time
=
vvv
.
Value
.
ReadDateTime
(
4
);
int
id
=
vvv
.
ReadInt
(
0
);
DateTime
time
=
vvv
.
ReadDateTime
(
4
);
DateTime
endTime
=
vvv
.
ReadDateTime
(
12
);
DateTime
endTime
=
vvv
.
Value
.
ReadDateTime
(
12
);
//mTagCount = vvv.ReadInt(24);//变量个数
mTagCount
=
vvv
.
Value
.
ReadInt
(
24
);
//变量个数
if
(
times
.
ContainsKey
(
id
))
{
times
[
id
].
Add
(
time
);
}
else
{
times
.
Add
(
id
,
new
List
<
DateTime
>()
{
time
});
}
times
.
Add
(
vvv
.
Key
,
time
);
maxTime
=
time
>
maxTime
?
time
:
maxTime
;
mLastModifyTime
=
endTime
>
mLastModifyTime
?
endTime
:
mLastModifyTime
;
}
mHeadAddress
=
GetDataRegionHeadPoint
(
vv
.
Key
,
times
,
maxTime
,
out
mwriter
);
//
long ltmp = sw.ElapsedMilliseconds;
long
ltmp
=
sw
.
ElapsedMilliseconds
;
mHeadValue
.
Clear
();
mwriter
.
GoToEnd
();
...
...
@@ -1040,21 +1052,34 @@ namespace Cdy.Tag
//写入数据,同时获取数据块地址
foreach
(
var
vvv
in
vv
.
Value
)
{
int
size
=
vvv
.
Value
.
ReadInt
(
20
);
mHeadValue
.
Add
(
vvv
.
Key
,
vpointer
);
vvv
.
Value
.
WriteToStream
(
mwriter
.
GetStream
(),
28
,
size
-
28
);
//直接拷贝数据块
int
id
=
vvv
.
ReadInt
(
0
);
int
size
=
vvv
.
ReadInt
(
20
);
if
(
mHeadValue
.
ContainsKey
(
id
))
{
mHeadValue
[
id
].
Add
(
vpointer
);
}
else
{
mHeadValue
.
Add
(
id
,
new
List
<
long
>()
{
vpointer
});
}
// mHeadValue.Add(vvv.Key, vpointer);
vvv
.
WriteToStream
(
mwriter
.
GetStream
(),
28
,
size
-
28
);
//直接拷贝数据块
vpointer
+=
(
size
-
28
);
}
//
long ltmp2 = sw.ElapsedMilliseconds;
long
ltmp2
=
sw
.
ElapsedMilliseconds
;
//更新数据块指针
foreach
(
var
hd
in
mHeadAddress
)
{
mwriter
.
Write
(
mHeadValue
[
hd
.
Key
],
hd
.
Value
);
for
(
int
i
=
0
;
i
<
hd
.
Value
.
Count
;
i
++)
{
mwriter
.
Write
(
mHeadValue
[
hd
.
Key
][
i
],
hd
.
Value
[
i
]);
}
//mwriter.Write(mHeadValue[hd.Key], hd.Value);
}
//
long ltmp3 = sw.ElapsedMilliseconds;
long
ltmp3
=
sw
.
ElapsedMilliseconds
;
//更新文件的最后修改时间
...
...
@@ -1072,43 +1097,12 @@ namespace Cdy.Tag
foreach
(
var
vvv
in
vv
.
Value
)
{
(
vvv
.
Value
as
MarshalMemoryBlock
).
MakeMemoryNoBusy
();
MarshalMemoryBlockPool
.
Pool
.
Release
(
vvv
.
Value
as
MarshalMemoryBlock
);
(
vvv
as
MarshalMemoryBlock
).
MakeMemoryNoBusy
();
MarshalMemoryBlockPool
.
Pool
.
Release
(
vvv
as
MarshalMemoryBlock
);
}
foreach
(
var
tm
in
times
)
{
var
vtime
=
FormateTime
(
tm
.
Value
);
//如果时间大于上次自动存储的时间,则需要将地址指针记录下来,等到下次自动存储内容更新时,将当前更新的数据的指针区同步过去
//仿制被覆盖过去
lock
(
mPointerCach
)
{
if
(
tm
.
Value
>
mCurrentTime
)
{
if
(
mPointerCach
.
ContainsKey
(
vtime
))
{
var
dd
=
mPointerCach
[
vtime
];
if
(
dd
.
ContainsKey
(
tm
.
Key
))
{
dd
[
tm
.
Key
]
=
mHeadValue
[
tm
.
Key
];
}
else
{
dd
.
Add
(
tm
.
Key
,
mHeadValue
[
tm
.
Key
]);
}
}
else
{
Dictionary
<
int
,
long
>
dtmp
=
new
Dictionary
<
int
,
long
>();
dtmp
.
Add
(
tm
.
Key
,
mHeadValue
[
tm
.
Key
]);
mPointerCach
.
Add
(
vtime
,
dtmp
);
}
}
}
}
//LoggerService.Service.Info("SeriseEnginer", "SeriseFileItem" + this.Id + " 完成存储,数据块:" + vv.Value.Count + " ReadHeadPoint:" + ltmp + " WriteData:" + (ltmp2 - ltmp) + " UpdateHead:" + (ltmp3 - ltmp2), ConsoleColor.Cyan);
LoggerService
.
Service
.
Info
(
"SeriseEnginer"
,
"SeriseFileItem"
+
this
.
Id
+
" 完成存储,数据块:"
+
vv
.
Value
.
Count
+
" ReadHeadPoint:"
+
ltmp
+
" WriteData:"
+
(
ltmp2
-
ltmp
)
+
" UpdateHead:"
+
(
ltmp3
-
ltmp2
),
ConsoleColor
.
Cyan
);
}
...
...
@@ -1131,7 +1125,7 @@ namespace Cdy.Tag
DateTime
time
=
datablock
.
ReadDateTime
(
4
);
DateTime
endTime
=
datablock
.
ReadDateTime
(
12
);
int
size
=
datablock
.
ReadInt
(
20
);
mTagCount
=
datablock
.
ReadInt
(
24
);
//变量个数
//
mTagCount = datablock.ReadInt(24);//变量个数
var
heads
=
GetDataRegionHeadPoint
(
id
,
time
,
out
mwriter
);
...
...
@@ -1160,34 +1154,34 @@ namespace Cdy.Tag
datablock
.
MakeMemoryNoBusy
();
MarshalMemoryBlockPool
.
Pool
.
Release
(
datablock
);
var
vtime
=
FormateTime
(
time
);
//
var vtime = FormateTime(time);
//如果时间大于上次自动存储的时间,则需要将地址指针记录下来,等到下次自动存储内容更新时,将当前更新的数据的指针区同步过去
//仿制被覆盖过去
lock
(
mPointerCach
)
{
if
(
time
>
mCurrentTime
)
{
if
(
mPointerCach
.
ContainsKey
(
vtime
))
{
var
dd
=
mPointerCach
[
vtime
];
if
(
dd
.
ContainsKey
(
id
))
{
dd
[
id
]
=
vpointer
;
}
else
{
dd
.
Add
(
id
,
vpointer
);
}
}
else
{
Dictionary
<
int
,
long
>
dtmp
=
new
Dictionary
<
int
,
long
>();
dtmp
.
Add
(
id
,
vpointer
);
mPointerCach
.
Add
(
vtime
,
dtmp
);
}
}
}
//
//
如果时间大于上次自动存储的时间,则需要将地址指针记录下来,等到下次自动存储内容更新时,将当前更新的数据的指针区同步过去
//
//
仿制被覆盖过去
//
lock (mPointerCach)
//
{
//
if (time > mCurrentTime)
//
{
//
if (mPointerCach.ContainsKey(vtime))
//
{
//
var dd = mPointerCach[vtime];
//
if (dd.ContainsKey(id))
//
{
//
dd[id] = vpointer;
//
}
//
else
//
{
//
dd.Add(id, vpointer);
//
}
//
}
//
else
//
{
//
Dictionary<int, long> dtmp = new Dictionary<int, long>();
//
dtmp.Add(id, vpointer);
//
mPointerCach.Add(vtime, dtmp);
//
}
//
}
//
}
}
}
...
...
@@ -1211,7 +1205,9 @@ namespace Cdy.Tag
private
int
CalTagIdsSize
()
{
if
(
mTagIdMemoryCach
!=
null
)
mTagIdMemoryCach
.
Dispose
();
mTagIdsCach
=
ServiceLocator
.
Locator
.
Resolve
<
IHisEngine2
>().
ListAllTags
().
Where
(
e
=>
e
.
Id
>=
Id
*
TagCountOneFile
&&
e
.
Id
<
(
Id
+
1
)
*
TagCountOneFile
).
OrderBy
(
e
=>
e
.
Id
).
Select
(
e
=>
e
.
Id
).
ToList
();
//mTagIdsCach = ServiceLocator.Locator.Resolve<IHisEngine2>().ListAllTags().Where(e => e.Id >= Id * TagCountOneFile && e.Id < (Id + 1) * TagCountOneFile).OrderBy(e => e.Id).Select(e => e.Id).ToList();
mTagIndexCach
.
Clear
();
mTagIdSum
=
0
;
...
...
@@ -1221,9 +1217,13 @@ namespace Cdy.Tag
int
preids
=
mTagIdsCach
[
0
];
mTagIdSum
+=
preids
;
mTagIdMemoryCach
.
WriteInt32
(
preids
);
mTagIndexCach
.
Add
(
preids
,
0
);
for
(
int
i
=
1
;
i
<
mTagIdsCach
.
Count
;
i
++)
{
var
id
=
mTagIdsCach
[
i
];
mTagIndexCach
.
Add
(
id
,
i
);
mTagIdMemoryCach
.
WriteInt32
(
id
-
preids
);
mTagIdSum
+=
id
;
preids
=
id
;
...
...
@@ -1242,13 +1242,19 @@ namespace Cdy.Tag
var
vv
=
ServiceLocator
.
Locator
.
Resolve
<
IHisEngine2
>();
var
tags
=
vv
.
ListAllTags
().
Where
(
e
=>
e
.
Id
>=
Id
*
TagCountOneFile
&&
e
.
Id
<
(
Id
+
1
)
*
TagCountOneFile
).
OrderBy
(
e
=>
e
.
Id
);
mTagIdsCach
=
tags
.
Select
(
e
=>
e
.
Id
).
ToList
();
if
(
mBlockPointMemory
!=
null
)
mBlockPointMemory
.
Dispose
();
mBlockPointMemory
=
new
MemoryBlock
(
tags
.
Count
()
*
8
,
4
*
1024
*
1024
);
mBlockPointMemory
.
Clear
();
LoggerService
.
Service
.
Info
(
"SeriseEnginer"
,
"Cal BlockPointMemory memory size:"
+
(
mBlockPointMemory
.
AllocSize
)
/
1024.0
/
1024
+
"M"
,
ConsoleColor
.
Cyan
);
CalTagIdsSize
();
mTagCount
=
mTagIdsCach
.
Count
();
LoggerService
.
Service
.
Info
(
"SeriseEnginer"
,
"Cal BlockPointMemory memory size:"
+
(
mBlockPointMemory
.
AllocSize
)
/
1024.0
/
1024
+
"M"
,
ConsoleColor
.
Cyan
);
}
/// <summary>
...
...
@@ -1356,7 +1362,7 @@ namespace Cdy.Tag
//数据大小
var
datasize
=
mProcessMemory
.
ReadInt
(
dataOffset
);
var
count
=
mProcessMemory
.
ReadInt
(
dataOffset
+
4
);
//变量个数
mTagCount
=
count
;
//
mTagCount = count;
mCurrentTime
=
time
;
var
ltmp
=
sw
.
ElapsedMilliseconds
;
...
...
@@ -1389,20 +1395,23 @@ namespace Cdy.Tag
mBlockPointMemory
.
CheckAndResize
(
mTagCount
*
8
);
mBlockPointMemory
.
Clear
();
var
vtime
=
FormateTime
(
time
);
Dictionary
<
int
,
long
>
timecach
;
lock
(
mPointerCach
)
{
if
(
mPointerCach
.
ContainsKey
(
time
))
{
timecach
=
mPointerCach
[
time
];
}
else
{
timecach
=
new
Dictionary
<
int
,
long
>();
}
}
Dictionary
<
int
,
long
>
mHeadValues
=
new
Dictionary
<
int
,
long
>();
var
vtime
=
FormateTime
(
time
);
//Dictionary<int, long> timecach;
//lock (mPointerCach)
//{
// if (mPointerCach.ContainsKey(time))
// {
// timecach = mPointerCach[time];
// }
// else
// {
// timecach = new Dictionary<int, long>();
// }
//}
//更新数据块指针
for
(
int
i
=
0
;
i
<
count
;
i
++)
...
...
@@ -1413,29 +1422,31 @@ namespace Cdy.Tag
offset
+=
8
;
if
(
id
>
-
1
)
{
//如果之前通过,手动记录已经更新了,则需要同步指针
if
(
timecach
.
ContainsKey
(
id
))
{
mBlockPointMemory
.
WriteLong
(
i
*
8
,
timecach
[
id
]);
}
else
{
mBlockPointMemory
.
WriteLong
(
i
*
8
,
addr
);
}
}
}
////如果之前通过,手动记录已经更新了,则需要同步指针
//if (timecach.ContainsKey(id))
//{
// mBlockPointMemory.WriteLong(i * 8, timecach[id]);
//}
//else
//{
//mBlockPointMemory.WriteLong(i * 8, addr);
//}
lock
(
mPointerCach
)
{
foreach
(
var
vv
in
mPointerCach
.
Keys
.
ToArray
())
{
if
(
vv
<=
mCurrentTime
)
{
mPointerCach
.
Remove
(
vv
);
}
mHeadValues
.
Add
(
id
,
addr
);
}
}
//lock (mPointerCach)
//{
// foreach (var vv in mPointerCach.Keys.ToArray())
// {
// if (vv <= mCurrentTime)
// {
// mPointerCach.Remove(vv);
// }
// }
//}
//计算本次更新对应的指针区域的起始地址
FileStartHour
=
(
time
.
Hour
/
FileDuration
)
*
FileDuration
;
...
...
@@ -1444,14 +1455,22 @@ namespace Cdy.Tag
//计算出本次更新的头地址地址
var
pointAddr
=
mBlockPointOffset
+
count
*
8
*
bid
;
var
ltmp3
=
sw
.
ElapsedMilliseconds
;
mFileWriter
.
GoToEnd
();
//long lpp = mFileWriter.CurrentPostion;
mProcessMemory
.
WriteToStream
(
mFileWriter
.
GetStream
(),
start
,
datasize
);
//直接拷贝数据块
//写入指针头部区域
mFileWriter
.
Write
(
mBlockPointMemory
.
Buffers
,
pointAddr
,
0
,
(
int
)
mBlockPointMemory
.
AllocSize
);
// mFileWriter.Write(mBlockPointMemory.Buffers, pointAddr, 0, (int)mBlockPointMemory.AllocSize);
foreach
(
var
vv
in
mHeadValues
)
{
mFileWriter
.
Write
(
pointAddr
+
mTagIndexCach
[
vv
.
Key
]
*
8
,
vv
.
Value
);
}
Flush
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录