Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
cdy816
Mars
提交
72b418e0
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 搜索 >>
提交
72b418e0
编写于
8月 17, 2020
作者:
cdy816
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
冗余功能添加
上级
bf6ad2e2
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
1213 addition
and
13 deletion
+1213
-13
Common/Cdy.Tag/Real/WorkState.cs
Common/Cdy.Tag/Real/WorkState.cs
+38
-0
RunTime/DBInRun/Program.cs
RunTime/DBInRun/Program.cs
+27
-7
RunTime/DBInRun/Properties/Resources.Designer.cs
RunTime/DBInRun/Properties/Resources.Designer.cs
+18
-0
RunTime/DBInRun/Properties/Resources.resx
RunTime/DBInRun/Properties/Resources.resx
+6
-0
RunTime/DBInRun/Properties/Resources.zh-CN.resx
RunTime/DBInRun/Properties/Resources.zh-CN.resx
+6
-0
RunTime/DBInRun/Properties/launchSettings.json
RunTime/DBInRun/Properties/launchSettings.json
+2
-1
RunTime/DBRuntime/RDDC/RDDCClient.cs
RunTime/DBRuntime/RDDC/RDDCClient.cs
+256
-0
RunTime/DBRuntime/RDDC/RDDCDataService.cs
RunTime/DBRuntime/RDDC/RDDCDataService.cs
+232
-0
RunTime/DBRuntime/RDDC/RDDCManager.cs
RunTime/DBRuntime/RDDC/RDDCManager.cs
+211
-0
RunTime/DBRuntime/RDDC/RDDCServerProcessBase.cs
RunTime/DBRuntime/RDDC/RDDCServerProcessBase.cs
+187
-0
RunTime/DBRuntime/RDDC/RealDataSyncServerProcess.cs
RunTime/DBRuntime/RDDC/RealDataSyncServerProcess.cs
+80
-0
RunTime/DBRuntime/RDDC/WorStateServerProcess.cs
RunTime/DBRuntime/RDDC/WorStateServerProcess.cs
+125
-0
RunTime/DBRuntime/Runner.cs
RunTime/DBRuntime/Runner.cs
+25
-5
未找到文件。
Common/Cdy.Tag/Real/WorkState.cs
0 → 100644
浏览文件 @
72b418e0
//==============================================================
// Copyright (C) 2020 Inc. All rights reserved.
//
//==============================================================
// Create by 种道洋 at 2020/8/17 13:24:21.
// Version 1.0
// 种道洋
//==============================================================
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Cdy.Tag
{
/// <summary>
///
/// </summary>
public
enum
WorkState
{
/// <summary>
/// 未知
/// </summary>
Unknow
,
/// <summary>
/// 工作机
/// </summary>
Primary
,
/// <summary>
/// 备份机
/// </summary>
Standby
,
/// <summary>
/// 切换中
/// </summary>
Switching
}
}
RunTime/DBInRun/Program.cs
浏览文件 @
72b418e0
...
@@ -13,9 +13,6 @@ namespace DBInRun
...
@@ -13,9 +13,6 @@ namespace DBInRun
{
{
static
bool
mIsClosed
=
false
;
static
bool
mIsClosed
=
false
;
static
Thread
mainThread
;
//static MarshalMemoryBlock block;
static
void
Main
(
string
[]
args
)
static
void
Main
(
string
[]
args
)
{
{
Console
.
CancelKeyPress
+=
Console_CancelKeyPress
;
Console
.
CancelKeyPress
+=
Console_CancelKeyPress
;
...
@@ -25,6 +22,9 @@ namespace DBInRun
...
@@ -25,6 +22,9 @@ namespace DBInRun
Console
.
WriteLine
(
Res
.
Get
(
"WelcomeMsg"
));
Console
.
WriteLine
(
Res
.
Get
(
"WelcomeMsg"
));
PrintLogo
();
PrintLogo
();
Console
.
WriteLine
(
Res
.
Get
(
"HelpMsg"
));
if
(
args
.
Length
>
0
&&
args
[
0
]==
"start"
)
if
(
args
.
Length
>
0
&&
args
[
0
]==
"start"
)
{
{
Task
.
Run
(()
=>
{
Task
.
Run
(()
=>
{
...
@@ -45,10 +45,7 @@ namespace DBInRun
...
@@ -45,10 +45,7 @@ namespace DBInRun
Cdy
.
Tag
.
Runner
.
RunInstance
.
Start
();
Cdy
.
Tag
.
Runner
.
RunInstance
.
Start
();
}
}
}
}
mainThread
=
Thread
.
CurrentThread
;
Console
.
WriteLine
(
Res
.
Get
(
"HelpMsg"
));
while
(!
mIsClosed
)
while
(!
mIsClosed
)
{
{
Console
.
Write
(
">"
);
Console
.
Write
(
">"
);
...
@@ -111,6 +108,9 @@ namespace DBInRun
...
@@ -111,6 +108,9 @@ namespace DBInRun
Cdy
.
Tag
.
Runner
.
RunInstance
.
ReStartDatabase
();
Cdy
.
Tag
.
Runner
.
RunInstance
.
ReStartDatabase
();
});
});
break
;
break
;
case
"list"
:
ListDatabase
();
break
;
case
"h"
:
case
"h"
:
Console
.
WriteLine
(
GetHelpString
());
Console
.
WriteLine
(
GetHelpString
());
break
;
break
;
...
@@ -121,6 +121,24 @@ namespace DBInRun
...
@@ -121,6 +121,24 @@ namespace DBInRun
}
}
}
}
/// <summary>
///
/// </summary>
private
static
void
ListDatabase
()
{
string
spath
=
System
.
IO
.
Path
.
GetDirectoryName
(
typeof
(
Program
).
Assembly
.
Location
);
spath
=
System
.
IO
.
Path
.
Combine
(
spath
,
"Data"
);
StringBuilder
sb
=
new
StringBuilder
();
string
stemp
=
"{0} {1}"
;
foreach
(
var
vv
in
System
.
IO
.
Directory
.
EnumerateDirectories
(
spath
))
{
var
vvn
=
new
System
.
IO
.
DirectoryInfo
(
vv
).
Name
;
string
sdb
=
System
.
IO
.
Path
.
Combine
(
vv
,
vvn
+
".db"
);
sb
.
AppendLine
(
string
.
Format
(
stemp
,
vvn
,
System
.
IO
.
File
.
GetLastWriteTime
(
sdb
)));
}
Console
.
WriteLine
(
sb
.
ToString
());
}
/// <summary>
/// <summary>
///
///
/// </summary>
/// </summary>
...
@@ -225,6 +243,8 @@ namespace DBInRun
...
@@ -225,6 +243,8 @@ namespace DBInRun
re
.
AppendLine
();
re
.
AppendLine
();
re
.
AppendLine
(
"start [database] // "
+
Res
.
Get
(
"StartMsg"
));
re
.
AppendLine
(
"start [database] // "
+
Res
.
Get
(
"StartMsg"
));
re
.
AppendLine
(
"stop // "
+
Res
.
Get
(
"StopMsg"
));
re
.
AppendLine
(
"stop // "
+
Res
.
Get
(
"StopMsg"
));
re
.
AppendLine
(
"restart // "
+
Res
.
Get
(
"RestartMsg"
));
re
.
AppendLine
(
"List // "
+
Res
.
Get
(
"ListMsg"
));
re
.
AppendLine
(
"h // "
+
Res
.
Get
(
"HMsg"
));
re
.
AppendLine
(
"h // "
+
Res
.
Get
(
"HMsg"
));
return
re
.
ToString
();
return
re
.
ToString
();
}
}
...
...
RunTime/DBInRun/Properties/Resources.Designer.cs
浏览文件 @
72b418e0
...
@@ -96,6 +96,24 @@ namespace DBInRun.Properties {
...
@@ -96,6 +96,24 @@ namespace DBInRun.Properties {
}
}
}
}
/// <summary>
/// 查找类似 List all databse 的本地化字符串。
/// </summary>
internal
static
string
ListMsg
{
get
{
return
ResourceManager
.
GetString
(
"ListMsg"
,
resourceCulture
);
}
}
/// <summary>
/// 查找类似 Qucik restarted a a database without pause it. 的本地化字符串。
/// </summary>
internal
static
string
RestartMsg
{
get
{
return
ResourceManager
.
GetString
(
"RestartMsg"
,
resourceCulture
);
}
}
/// <summary>
/// <summary>
/// 查找类似 start to run a databse,ignor database name to run default 'local' database 的本地化字符串。
/// 查找类似 start to run a databse,ignor database name to run default 'local' database 的本地化字符串。
/// </summary>
/// </summary>
...
...
RunTime/DBInRun/Properties/Resources.resx
浏览文件 @
72b418e0
...
@@ -129,6 +129,12 @@
...
@@ -129,6 +129,12 @@
<data
name=
"HMsg"
xml:space=
"preserve"
>
<data
name=
"HMsg"
xml:space=
"preserve"
>
<value>
display command list
</value>
<value>
display command list
</value>
</data>
</data>
<data
name=
"ListMsg"
xml:space=
"preserve"
>
<value>
List all databse
</value>
</data>
<data
name=
"RestartMsg"
xml:space=
"preserve"
>
<value>
Qucik restarted a a database without pause it.
</value>
</data>
<data
name=
"StartMsg"
xml:space=
"preserve"
>
<data
name=
"StartMsg"
xml:space=
"preserve"
>
<value>
start to run a databse,ignor database name to run default 'local' database
</value>
<value>
start to run a databse,ignor database name to run default 'local' database
</value>
</data>
</data>
...
...
RunTime/DBInRun/Properties/Resources.zh-CN.resx
浏览文件 @
72b418e0
...
@@ -129,6 +129,12 @@
...
@@ -129,6 +129,12 @@
<data
name=
"HMsg"
xml:space=
"preserve"
>
<data
name=
"HMsg"
xml:space=
"preserve"
>
<value>
显示命令列表
</value>
<value>
显示命令列表
</value>
</data>
</data>
<data
name=
"ListMsg"
xml:space=
"preserve"
>
<value>
列出所有的数据库
</value>
</data>
<data
name=
"RestartMsg"
xml:space=
"preserve"
>
<value>
在不中断的情况下快速启动数据库
</value>
</data>
<data
name=
"StartMsg"
xml:space=
"preserve"
>
<data
name=
"StartMsg"
xml:space=
"preserve"
>
<value>
运行指定数据库,如果忽略数据库名称则启动默认'local'数据库
</value>
<value>
运行指定数据库,如果忽略数据库名称则启动默认'local'数据库
</value>
</data>
</data>
...
...
RunTime/DBInRun/Properties/launchSettings.json
浏览文件 @
72b418e0
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
"profiles"
:
{
"profiles"
:
{
"DBInRun"
:
{
"DBInRun"
:
{
"commandName"
:
"Executable"
,
"commandName"
:
"Executable"
,
"executablePath"
:
"C:
\\
Users
\\
cdy81
\\
source
\\
repos
\\
mars
\\
Output
\\
DBInRun.exe"
"executablePath"
:
"C:
\\
Users
\\
chongdaoyang
\\
source
\\
repos
\\
mars
\\
Output
\\
DBInRun.exe"
,
"commandLineArgs"
:
"start test1 37000"
}
}
}
}
}
}
\ No newline at end of file
RunTime/DBRuntime/RDDC/RDDCClient.cs
0 → 100644
浏览文件 @
72b418e0
//==============================================================
// Copyright (C) 2020 Inc. All rights reserved.
//
//==============================================================
// Create by 种道洋 at 2020/8/17 17:03:59.
// Version 1.0
// 种道洋
//==============================================================
using
Cdy.Tag
;
using
DotNetty.Buffers
;
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Text
;
using
System.Threading
;
namespace
DBRuntime.RDDC
{
/// <summary>
///
/// </summary>
public
class
RDDCClient
:
SocketClient
{
#
region
...
Variables
...
/// <summary>
///
/// </summary>
public
const
byte
WorkStateFun
=
1
;
/// <summary>
///
/// </summary>
public
const
byte
RealDataSyncFun
=
2
;
public
const
byte
AysncReturn
=
byte
.
MaxValue
;
/// <summary>
/// 获取启动时间
/// </summary>
public
const
byte
GetStartTimeFun
=
0
;
/// <summary>
/// 切换到从机
/// </summary>
public
const
byte
ChangeToStandbyFun
=
1
;
/// <summary>
/// 切换同主机
/// </summary>
public
const
byte
ChangeToPrimaryFun
=
2
;
/// <summary>
/// 获取工作状态
/// </summary>
public
const
byte
GetStateFun
=
3
;
private
ManualResetEvent
mWorkStateEvent
=
new
ManualResetEvent
(
false
);
private
IByteBuffer
mWorkStateData
;
private
ManualResetEvent
mRealDataSyncEvent
=
new
ManualResetEvent
(
false
);
private
IByteBuffer
mRealDataSyncData
;
#
endregion
...
Variables
...
#
region
...
Events
...
#
endregion
...
Events
...
#
region
...
Constructor
...
#
endregion
...
Constructor
...
#
region
...
Properties
...
#
endregion
...
Properties
...
#
region
...
Methods
...
/// <summary>
///
/// </summary>
/// <param name="fun"></param>
/// <param name="datas"></param>
protected
override
void
ProcessData
(
byte
fun
,
IByteBuffer
datas
)
{
datas
.
Retain
();
//收到异步请求回调数据
if
(
datas
.
ReadableBytes
==
1
)
{
if
(
datas
.
ReadByte
()
==
byte
.
MaxValue
)
return
;
else
{
Debug
.
Print
(
"DbClient ProcessData Invailed data"
);
}
}
else
{
switch
(
fun
)
{
case
WorkStateFun
:
mWorkStateData
=
datas
;
mWorkStateEvent
.
Set
();
break
;
case
RealDataSyncFun
:
mRealDataSyncData
=
datas
;
this
.
mRealDataSyncEvent
.
Set
();
break
;
}
}
base
.
ProcessData
(
fun
,
datas
);
}
/// <summary>
///
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public
IByteBuffer
SyncRealData
(
int
timeout
=
5000
)
{
var
mb
=
GetBuffer
(
RealDataSyncFun
,
0
);
mRealDataSyncEvent
.
Reset
();
Send
(
mb
);
try
{
if
(
mRealDataSyncEvent
.
WaitOne
(
timeout
))
{
return
mRealDataSyncData
;
}
}
finally
{
}
return
null
;
}
/// <summary>
///
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public
DateTime
?
GetStartTime
(
int
timeout
=
5000
)
{
var
mb
=
GetBuffer
(
WorkStateFun
,
1
);
mb
.
WriteByte
(
GetStartTimeFun
);
mWorkStateEvent
.
Reset
();
Send
(
mb
);
try
{
if
(
mWorkStateEvent
.
WaitOne
(
timeout
))
{
return
DateTime
.
FromBinary
(
mWorkStateData
.
ReadLong
());
}
}
finally
{
}
return
null
;
}
/// <summary>
///
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public
WorkState
?
GetWorkState
(
int
timeout
=
5000
)
{
var
mb
=
GetBuffer
(
WorkStateFun
,
1
);
mb
.
WriteByte
(
GetStateFun
);
mWorkStateEvent
.
Reset
();
Send
(
mb
);
try
{
if
(
mWorkStateEvent
.
WaitOne
(
timeout
))
{
return
(
WorkState
)
mWorkStateData
.
ReadByte
();
}
}
finally
{
}
return
null
;
}
/// <summary>
///
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public
bool
?
SwitchToPrimary
(
int
timeout
=
5000
)
{
var
mb
=
GetBuffer
(
WorkStateFun
,
1
);
mb
.
WriteByte
(
ChangeToPrimaryFun
);
mWorkStateEvent
.
Reset
();
Send
(
mb
);
try
{
if
(
mWorkStateEvent
.
WaitOne
(
timeout
))
{
return
mWorkStateData
.
ReadByte
()>
0
;
}
}
finally
{
}
return
null
;
}
/// <summary>
///
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public
bool
?
SwitchToStandby
(
int
timeout
=
5000
)
{
var
mb
=
GetBuffer
(
WorkStateFun
,
1
);
mb
.
WriteByte
(
ChangeToStandbyFun
);
mWorkStateEvent
.
Reset
();
Send
(
mb
);
try
{
if
(
mWorkStateEvent
.
WaitOne
(
timeout
))
{
return
mWorkStateData
.
ReadByte
()
>
0
;
}
}
finally
{
}
return
null
;
}
#
endregion
...
Methods
...
#
region
...
Interfaces
...
#
endregion
...
Interfaces
...
}
}
RunTime/DBRuntime/RDDC/RDDCDataService.cs
0 → 100644
浏览文件 @
72b418e0
//==============================================================
// Copyright (C) 2020 Inc. All rights reserved.
//
//==============================================================
// Create by 种道洋 at 2020/5/14 10:22:00.
// Version 1.0
// 种道洋
//==============================================================
using
Cdy.Tag
;
using
DotNetty.Buffers
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
DBRuntime.RDDC
{
public
class
ApiFunConst
{
/// <summary>
///
/// </summary>
public
const
byte
WorkStateFun
=
1
;
/// <summary>
///
/// </summary>
public
const
byte
RealDataSyncFun
=
2
;
public
const
byte
AysncReturn
=
byte
.
MaxValue
;
}
/// <summary>
///
/// </summary>
public
class
RDDCDataService
:
SocketServer
{
#
region
...
Variables
...
private
IByteBuffer
mAsyncCalldata
;
private
Dictionary
<
byte
,
RDDCServerProcessBase
>
mProcess
=
new
Dictionary
<
byte
,
RDDCServerProcessBase
>();
private
WorStateServerProcess
mWorkStateProcess
;
private
RealDataSyncServerProcess
mRealDataSyncProcess
;
/// <summary>
///
/// </summary>
public
static
RDDCDataService
Service
=
new
RDDCDataService
();
/// <summary>
///
/// </summary>
public
override
string
Name
=>
"RDDCDataService"
;
#
endregion
...
Variables
...
#
region
...
Events
...
#
endregion
...
Events
...
#
region
...
Constructor
...
/// <summary>
///
/// </summary>
public
RDDCDataService
()
{
RegistorInit
();
}
#
endregion
...
Constructor
...
#
region
...
Properties
...
#
endregion
...
Properties
...
#
region
...
Methods
...
/// <summary>
///
/// </summary>
/// <param name="port"></param>
protected
override
void
StartInner
(
int
port
)
{
mWorkStateProcess
=
new
WorStateServerProcess
()
{
Parent
=
this
};
mRealDataSyncProcess
=
new
RealDataSyncServerProcess
()
{
Parent
=
this
};
mWorkStateProcess
.
Start
();
mRealDataSyncProcess
.
Start
();
base
.
StartInner
(
port
);
}
/// <summary>
///
/// </summary>
public
override
void
Stop
()
{
base
.
Stop
();
if
(
mWorkStateProcess
!=
null
)
{
mWorkStateProcess
.
Stop
();
mWorkStateProcess
.
Dispose
();
mWorkStateProcess
=
null
;
}
if
(
mRealDataSyncProcess
!=
null
)
{
mRealDataSyncProcess
.
Stop
();
mRealDataSyncProcess
.
Dispose
();
mRealDataSyncProcess
=
null
;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
private
IByteBuffer
GetAsyncData
()
{
mAsyncCalldata
=
BufferManager
.
Manager
.
Allocate
(
ApiFunConst
.
AysncReturn
,
4
);
mAsyncCalldata
.
WriteInt
(
0
);
return
mAsyncCalldata
;
}
/// <summary>
///
/// </summary>
private
void
RegistorInit
()
{
this
.
RegistorFunCallBack
(
ApiFunConst
.
WorkStateFun
,
WorkStateProcess
);
this
.
RegistorFunCallBack
(
ApiFunConst
.
RealDataSyncFun
,
RealDataSyncProcess
);
}
/// <summary>
///
/// </summary>
public
void
PushRealDatatoClient
(
string
clientId
,
byte
[]
value
)
{
this
.
SendData
(
clientId
,
Api
.
ApiFunConst
.
RealDataPushFun
,
value
,
value
.
Length
);
}
/// <summary>
///
/// </summary>
/// <param name="clientId"></param>
/// <param name="value"></param>
public
void
PushRealDatatoClient
(
string
clientId
,
IByteBuffer
value
)
{
this
.
SendData
(
clientId
,
value
);
}
/// <summary>
///
/// </summary>
/// <param name="clientId"></param>
/// <param name="fun"></param>
/// <param name="value"></param>
public
void
AsyncCallback
(
string
clientId
,
byte
fun
,
byte
[]
value
,
int
len
)
{
this
.
SendData
(
clientId
,
fun
,
value
,
len
);
}
/// <summary>
///
/// </summary>
/// <param name="clientId"></param>
/// <param name="data"></param>
public
void
AsyncCallback
(
string
clientId
,
IByteBuffer
data
)
{
this
.
SendData
(
clientId
,
data
);
}
/// <summary>
///
/// </summary>
/// <param name="clientId"></param>
/// <param name="fun"></param>
/// <param name="value"></param>
/// <param name="len"></param>
public
void
AsyncCallback
(
string
clientId
,
byte
fun
,
IntPtr
value
,
int
len
)
{
this
.
SendData
(
clientId
,
fun
,
value
,
len
);
}
/// <summary>
///
/// </summary>
/// <param name="clientId"></param>
/// <param name="memory"></param>
/// <returns></returns>
private
IByteBuffer
WorkStateProcess
(
string
clientId
,
IByteBuffer
memory
)
{
this
.
mWorkStateProcess
.
ProcessData
(
clientId
,
memory
);
return
GetAsyncData
();
}
/// <summary>
///
/// </summary>
/// <param name="clientId"></param>
/// <param name="memory"></param>
/// <returns></returns>
private
IByteBuffer
RealDataSyncProcess
(
string
clientId
,
IByteBuffer
memory
)
{
this
.
mRealDataSyncProcess
.
ProcessData
(
clientId
,
memory
);
return
GetAsyncData
();
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
protected
override
void
OnClientDisConnected
(
string
id
)
{
mRealDataSyncProcess
.
OnClientDisconnected
(
id
);
this
.
mWorkStateProcess
.
OnClientDisconnected
(
id
);
ServiceLocator
.
Locator
.
Resolve
<
IRuntimeSecurity
>().
LogoutByClientId
(
id
);
base
.
OnClientDisConnected
(
id
);
}
#
endregion
...
Methods
...
#
region
...
Interfaces
...
#
endregion
...
Interfaces
...
}
}
RunTime/DBRuntime/RDDC/RDDCManager.cs
0 → 100644
浏览文件 @
72b418e0
//==============================================================
// Copyright (C) 2020 Inc. All rights reserved.
//
//==============================================================
// Create by 种道洋 at 2020/8/17 16:34:14.
// Version 1.0
// 种道洋
//==============================================================
using
Cdy.Tag
;
using
DBRuntime.RDDC
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
DBRuntime
{
public
class
RDDCManager
{
#
region
...
Variables
...
/// <summary>
///
/// </summary>
public
static
RDDCManager
Manager
=
new
RDDCManager
();
private
RDDCDataService
mServer
;
private
RDDCClient
mClient
;
private
bool
mIsInited
=
false
;
private
object
mLockObj
=
new
object
();
#
endregion
...
Variables
...
#
region
...
Events
...
#
endregion
...
Events
...
#
region
...
Constructor
...
public
RDDCManager
()
{
}
#
endregion
...
Constructor
...
#
region
...
Properties
...
/// <summary>
/// 当前状态
/// </summary>
public
WorkState
CurrentState
{
get
;
set
;
}
=
WorkState
.
Unknow
;
/// <summary>
///
/// </summary>
public
DateTime
StartTime
{
get
;
set
;
}
/// <summary>
/// 服务端口
/// </summary>
public
int
Port
{
get
;
set
;
}
/// <summary>
///
/// </summary>
public
string
RemoteIp
{
get
;
set
;
}
/// <summary>
///
/// </summary>
public
Func
<
WorkState
,
bool
>
SwitchWorkStateAction
{
get
;
set
;
}
#
endregion
...
Properties
...
#
region
...
Methods
...
/// <summary>
///
/// </summary>
public
void
Start
()
{
mIsInited
=
false
;
mServer
=
new
RDDCDataService
();
mServer
.
Start
(
Port
);
mClient
=
new
RDDCClient
();
mClient
.
Connect
(
RemoteIp
,
Port
);
mClient
.
PropertyChanged
+=
MClient_PropertyChanged
;
CheckWorkState
();
mIsInited
=
true
;
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
MClient_PropertyChanged
(
object
sender
,
System
.
ComponentModel
.
PropertyChangedEventArgs
e
)
{
if
(
mIsInited
)
{
Task
.
Run
(
ProcessClientConnectChanged
);
}
}
/// <summary>
///
/// </summary>
public
void
Stop
()
{
mServer
.
Stop
();
mClient
.
Close
();
}
private
void
ProcessClientConnectChanged
()
{
if
(!
mClient
.
IsConnected
)
{
if
(
CurrentState
!=
WorkState
.
Primary
)
SwitchTo
(
WorkState
.
Primary
);
}
else
{
var
state
=
mClient
.
GetWorkState
();
if
((
state
==
WorkState
.
Primary
&&
this
.
CurrentState
==
WorkState
.
Primary
)
||
(
state
==
WorkState
.
Standby
&&
this
.
CurrentState
==
WorkState
.
Standby
))
{
var
time
=
mClient
.
GetStartTime
();
var
ss
=
time
>
this
.
StartTime
?
WorkState
.
Primary
:
WorkState
.
Standby
;
SwitchTo
(
ss
);
}
}
}
/// <summary>
///
/// </summary>
private
void
CheckWorkState
()
{
int
count
=
0
;
while
(!
mClient
.
IsConnected
)
{
Thread
.
Sleep
(
100
);
count
++;
if
(
count
>
30
)
break
;
}
if
(!
mClient
.
IsConnected
)
{
CurrentState
=
WorkState
.
Primary
;
}
else
{
var
time
=
mClient
.
GetStartTime
();
if
(
time
!=
null
)
{
CurrentState
=
time
>
this
.
StartTime
?
WorkState
.
Primary
:
WorkState
.
Standby
;
}
else
{
CurrentState
=
WorkState
.
Standby
;
}
}
}
/// <summary>
///
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public
bool
SwitchTo
(
WorkState
state
)
{
lock
(
mLockObj
)
{
var
olds
=
CurrentState
;
CurrentState
=
WorkState
.
Switching
;
if
(
SwitchWorkStateAction
!=
null
)
{
if
(
SwitchWorkStateAction
(
state
))
{
CurrentState
=
state
;
return
true
;
}
else
{
CurrentState
=
olds
;
return
false
;
}
}
CurrentState
=
state
;
return
true
;
}
}
#
endregion
...
Methods
...
#
region
...
Interfaces
...
#
endregion
...
Interfaces
...
}
}
RunTime/DBRuntime/RDDC/RDDCServerProcessBase.cs
0 → 100644
浏览文件 @
72b418e0
//==============================================================
// Copyright (C) 2020 Inc. All rights reserved.
//
//==============================================================
// Create by 种道洋 at 2020/5/14 11:01:03.
// Version 1.0
// 种道洋
//==============================================================
using
Cdy.Tag
;
using
DotNetty.Buffers
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Threading
;
namespace
DBRuntime.RDDC
{
public
abstract
class
RDDCServerProcessBase
:
IDisposable
{
#
region
...
Variables
...
/// <summary>
///
/// </summary>
private
Dictionary
<
string
,
Queue
<
IByteBuffer
>>
mDatasCach
=
new
Dictionary
<
string
,
Queue
<
IByteBuffer
>>();
private
Thread
mProcessThread
;
private
ManualResetEvent
resetEvent
;
private
bool
mIsClosed
=
false
;
#
endregion
...
Variables
...
#
region
...
Events
...
#
endregion
...
Events
...
#
region
...
Constructor
...
#
endregion
...
Constructor
...
#
region
...
Properties
...
/// <summary>
///
/// </summary>
public
abstract
byte
FunId
{
get
;
}
/// <summary>
///
/// </summary>
public
RDDCDataService
Parent
{
get
;
set
;
}
#
endregion
...
Properties
...
#
region
...
Methods
...
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
protected
IByteBuffer
ToByteBuffer
(
byte
id
,
string
value
)
{
var
re
=
BufferManager
.
Manager
.
Allocate
(
id
,
value
.
Length
*
2
);
re
.
WriteString
(
value
);
return
re
;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="value"></param>
/// <returns></returns>
protected
IByteBuffer
ToByteBuffer
(
byte
id
,
byte
value
)
{
var
re
=
BufferManager
.
Manager
.
Allocate
(
id
,
1
);
re
.
WriteByte
(
value
);
return
re
;
}
protected
IByteBuffer
ToByteBuffer
(
byte
id
,
long
value
)
{
var
re
=
BufferManager
.
Manager
.
Allocate
(
id
,
1
);
re
.
WriteLong
(
value
);
return
re
;
}
/// <summary>
///
/// </summary>
/// <param name="data"></param>
public
virtual
void
ProcessData
(
string
client
,
IByteBuffer
data
)
{
data
.
Retain
();
if
(
mDatasCach
.
ContainsKey
(
client
))
{
mDatasCach
[
client
].
Enqueue
(
data
);
}
else
{
var
vq
=
new
Queue
<
IByteBuffer
>();
vq
.
Enqueue
(
data
);
mDatasCach
.
Add
(
client
,
vq
);
}
resetEvent
.
Set
();
}
/// <summary>
///
/// </summary>
private
void
DataProcess
()
{
while
(!
mIsClosed
)
{
resetEvent
.
WaitOne
();
if
(
mIsClosed
)
return
;
resetEvent
.
Reset
();
foreach
(
var
vv
in
mDatasCach
)
{
while
(
vv
.
Value
.
Count
>
0
)
{
var
dd
=
vv
.
Value
.
Dequeue
();
ProcessSingleData
(
vv
.
Key
,
dd
);
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="client"></param>
/// <param name="data"></param>
protected
virtual
void
ProcessSingleData
(
string
client
,
IByteBuffer
data
)
{
data
.
ReleaseBuffer
();
}
public
virtual
void
Start
()
{
resetEvent
=
new
ManualResetEvent
(
false
);
mProcessThread
=
new
Thread
(
DataProcess
);
mProcessThread
.
IsBackground
=
true
;
mProcessThread
.
Start
();
}
/// <summary>
///
/// </summary>
public
virtual
void
Stop
()
{
mIsClosed
=
true
;
resetEvent
.
Set
();
resetEvent
.
Close
();
}
/// <summary>
///
/// </summary>
public
virtual
void
Dispose
()
{
Parent
=
null
;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
public
virtual
void
OnClientDisconnected
(
string
id
)
{
}
#
endregion
...
Methods
...
#
region
...
Interfaces
...
#
endregion
...
Interfaces
...
}
}
RunTime/DBRuntime/RDDC/RealDataSyncServerProcess.cs
0 → 100644
浏览文件 @
72b418e0
//==============================================================
// Copyright (C) 2020 Inc. All rights reserved.
//
//==============================================================
// Create by 种道洋 at 2020/8/17 15:52:53.
// Version 1.0
// 种道洋
//==============================================================
using
Cdy.Tag
;
using
DBRuntime.Api
;
using
DotNetty.Buffers
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
DBRuntime.RDDC
{
public
class
RealDataSyncServerProcess
:
RDDCServerProcessBase
{
#
region
...
Variables
...
#
endregion
...
Variables
...
#
region
...
Events
...
#
endregion
...
Events
...
#
region
...
Constructor
...
#
endregion
...
Constructor
...
#
region
...
Properties
...
/// <summary>
///
/// </summary>
public
override
byte
FunId
=>
2
;
#
endregion
...
Properties
...
#
region
...
Methods
...
/// <summary>
///
/// </summary>
/// <param name="client"></param>
/// <param name="data"></param>
protected
override
void
ProcessSingleData
(
string
client
,
IByteBuffer
data
)
{
ProcessRealDataSync
(
client
);
base
.
ProcessSingleData
(
client
,
data
);
}
/// <summary>
///
/// </summary>
/// <param name="clientId"></param>
private
void
ProcessRealDataSync
(
string
clientId
)
{
var
service
=
ServiceLocator
.
Locator
.
Resolve
<
IRealData
>();
var
real
=
(
service
as
RealEnginer
);
var
re
=
BufferManager
.
Manager
.
Allocate
(
ApiFunConst
.
RealDataSyncFun
,
4
);
re
.
WriteInt
(
real
.
Memory
.
Length
);
re
=
Unpooled
.
CompositeBuffer
().
AddComponents
(
true
,
re
,
Unpooled
.
WrappedBuffer
(
real
.
Memory
,
0
,
real
.
Memory
.
Length
));
Parent
.
AsyncCallback
(
clientId
,
re
);
}
#
endregion
...
Methods
...
#
region
...
Interfaces
...
#
endregion
...
Interfaces
...
}
}
RunTime/DBRuntime/RDDC/WorStateServerProcess.cs
0 → 100644
浏览文件 @
72b418e0
//==============================================================
// Copyright (C) 2020 Inc. All rights reserved.
//
//==============================================================
// Create by 种道洋 at 2020/8/17 15:50:59.
// Version 1.0
// 种道洋
//==============================================================
using
DBRuntime.Api
;
using
DotNetty.Buffers
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
DBRuntime.RDDC
{
public
class
WorStateServerProcess
:
RDDCServerProcessBase
{
#
region
...
Variables
...
/// <summary>
/// 获取启动时间
/// </summary>
public
const
byte
GetStartTime
=
0
;
/// <summary>
/// 切换到从机
/// </summary>
public
const
byte
ChangeToStandby
=
1
;
/// <summary>
/// 切换同主机
/// </summary>
public
const
byte
ChangeToPrimary
=
2
;
/// <summary>
/// 获取工作状态
/// </summary>
public
const
byte
GetState
=
3
;
#
endregion
...
Variables
...
#
region
...
Events
...
#
endregion
...
Events
...
#
region
...
Constructor
...
#
endregion
...
Constructor
...
#
region
...
Properties
...
/// <summary>
///
/// </summary>
public
override
byte
FunId
=>
1
;
#
endregion
...
Properties
...
#
region
...
Methods
...
/// <summary>
///
/// </summary>
/// <param name="client"></param>
/// <param name="data"></param>
protected
override
void
ProcessSingleData
(
string
client
,
IByteBuffer
data
)
{
byte
cmd
=
data
.
ReadByte
();
switch
(
cmd
)
{
case
GetStartTime
:
ProcessGetStartTime
(
client
);
break
;
case
ChangeToPrimary
:
var
re
=
ProcessSwichToPrimary
();
Parent
.
AsyncCallback
(
client
,
ToByteBuffer
(
GetStartTime
,
re
?
1
:
0
));
break
;
case
ChangeToStandby
:
re
=
ProcessSwichToStandby
();
Parent
.
AsyncCallback
(
client
,
ToByteBuffer
(
GetStartTime
,
re
?
1
:
0
));
break
;
case
GetState
:
var
state
=
(
byte
)
RDDCManager
.
Manager
.
CurrentState
;
Parent
.
AsyncCallback
(
client
,
ToByteBuffer
(
GetStartTime
,
state
));
break
;
}
base
.
ProcessSingleData
(
client
,
data
);
}
/// <summary>
///
/// </summary>
private
void
ProcessGetStartTime
(
string
client
)
{
Parent
.
AsyncCallback
(
client
,
ToByteBuffer
(
GetStartTime
,
RDDCManager
.
Manager
.
StartTime
.
ToBinary
()));
}
/// <summary>
///
/// </summary>
/// <returns></returns>
private
bool
ProcessSwichToPrimary
()
{
return
RDDCManager
.
Manager
.
SwitchTo
(
Cdy
.
Tag
.
WorkState
.
Primary
);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
private
bool
ProcessSwichToStandby
()
{
return
RDDCManager
.
Manager
.
SwitchTo
(
Cdy
.
Tag
.
WorkState
.
Standby
);
}
#
endregion
...
Methods
...
#
region
...
Interfaces
...
#
endregion
...
Interfaces
...
}
}
RunTime/DBRuntime/Runner.cs
浏览文件 @
72b418e0
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
// 种道洋
// 种道洋
//==============================================================
//==============================================================
using
Cdy.Tag.Driver
;
using
Cdy.Tag.Driver
;
using
DBRuntime
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Diagnostics
;
...
@@ -75,6 +76,8 @@ namespace Cdy.Tag
...
@@ -75,6 +76,8 @@ namespace Cdy.Tag
/// </summary>
/// </summary>
static
Runner
()
static
Runner
()
{
{
RDDCManager
.
Manager
.
StartTime
=
DateTime
.
Now
;
//注册日志
//注册日志
ServiceLocator
.
Locator
.
Registor
<
ILog
>(
new
ConsoleLogger
());
ServiceLocator
.
Locator
.
Registor
<
ILog
>(
new
ConsoleLogger
());
...
@@ -86,6 +89,18 @@ namespace Cdy.Tag
...
@@ -86,6 +89,18 @@ namespace Cdy.Tag
#
region
...
Properties
...
#
region
...
Properties
...
/// <summary>
///
/// </summary>
public
WorkState
State
{
get
{
return
RDDCManager
.
Manager
.
CurrentState
;
}
}
/// <summary>
/// <summary>
/// 数据库存访路径
/// 数据库存访路径
/// </summary>
/// </summary>
...
@@ -317,17 +332,22 @@ namespace Cdy.Tag
...
@@ -317,17 +332,22 @@ namespace Cdy.Tag
public
async
void
StartAsync
(
string
database
,
int
port
=
14330
)
public
async
void
StartAsync
(
string
database
,
int
port
=
14330
)
{
{
LoggerService
.
Service
.
Info
(
"Runner"
,
" 数据库 "
+
database
+
" 开始启动"
);
LoggerService
.
Service
.
Info
(
"Runner"
,
" 数据库 "
+
database
+
" 开始启动"
);
RDDCManager
.
Manager
.
Start
();
var
re
=
await
InitAsync
(
database
);
var
re
=
await
InitAsync
(
database
);
if
(!
re
)
if
(!
re
)
{
{
return
;
return
;
}
}
DBRuntime
.
Api
.
DataService
.
Service
.
Start
(
port
);
DBRuntime
.
Api
.
DataService
.
Service
.
Start
(
port
);
seriseEnginer
.
Start
();
compressEnginer
.
Start
();
if
(
RDDCManager
.
Manager
.
CurrentState
==
WorkState
.
Primary
)
hisEnginer
.
Start
();
{
//mSecurityRunner.Start();
seriseEnginer
.
Start
();
DriverManager
.
Manager
.
Start
();
compressEnginer
.
Start
();
hisEnginer
.
Start
();
DriverManager
.
Manager
.
Start
();
}
mIsStarted
=
true
;
mIsStarted
=
true
;
LoggerService
.
Service
.
Info
(
"Runner"
,
" 数据库 "
+
database
+
" 启动完成"
);
LoggerService
.
Service
.
Info
(
"Runner"
,
" 数据库 "
+
database
+
" 启动完成"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录