From b160fae3fa7e25607cb7b139d7a6a9a455f59c2d Mon Sep 17 00:00:00 2001 From: TianMaiCheng <746290578@qq.com> Date: Fri, 26 Dec 2025 16:17:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B2=A1=E7=94=A8=E7=9A=84=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=EF=BC=8C=E5=B9=B2=E6=89=B0=E8=A7=86=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 + Faster/Faster.csproj | 14 ---- Faster/Program.cs | 28 ------- MyFaster/LengRe.cs | 98 ---------------------- MyFaster/MyFaster.csproj | 17 ---- MyFaster/MyFun.cs | 98 ---------------------- MyFaster/Program.cs | 108 ------------------------- MyFunctioncache/MyFunctioncache.csproj | 14 ---- MyFunctioncache/Program.cs | 41 ---------- mypwsh/Program.cs | 24 ------ mypwsh/mypwsh.csproj | 15 ---- 11 files changed, 4 insertions(+), 457 deletions(-) delete mode 100644 Faster/Faster.csproj delete mode 100644 Faster/Program.cs delete mode 100644 MyFaster/LengRe.cs delete mode 100644 MyFaster/MyFaster.csproj delete mode 100644 MyFaster/MyFun.cs delete mode 100644 MyFaster/Program.cs delete mode 100644 MyFunctioncache/MyFunctioncache.csproj delete mode 100644 MyFunctioncache/Program.cs delete mode 100644 mypwsh/Program.cs delete mode 100644 mypwsh/mypwsh.csproj diff --git a/.gitignore b/.gitignore index 647f98c..0e32ff0 100644 --- a/.gitignore +++ b/.gitignore @@ -86,3 +86,7 @@ /mypwsh/bin /回收/bin /消费/bin +/Faster +/MyFaster +/MyFunctioncache +/mypwsh diff --git a/Faster/Faster.csproj b/Faster/Faster.csproj deleted file mode 100644 index 94c86b5..0000000 --- a/Faster/Faster.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Exe - net8.0 - enable - enable - - - - - - - diff --git a/Faster/Program.cs b/Faster/Program.cs deleted file mode 100644 index bc36ed6..0000000 --- a/Faster/Program.cs +++ /dev/null @@ -1,28 +0,0 @@ -using FASTER.core; - -namespace Faster -{ - internal class Program - { - static void Main(string[] args) - { - using var settings = new FasterKVSettings("c:/temp"); // backing storage device - using var store = new FasterKV(settings); - - // Create a session per sequence of interactions with FASTER - // We use default callback functions with a custom merger: RMW merges input by adding it to value - using var session = store.NewSession(new SimpleFunctions((a, b) => a + b)); - - long key = 1, value = 1, input = 10, output = 0; - - // Upsert and Read - session.Upsert(ref key, ref value); - session.Read(ref key, ref output); - - // Read-Modify-Write (add input to value) - session.RMW(ref key, ref input); - session.RMW(ref key, ref input, ref output); - Console.WriteLine("Hello, World!"); - } - } -} diff --git a/MyFaster/LengRe.cs b/MyFaster/LengRe.cs deleted file mode 100644 index b9d26d4..0000000 --- a/MyFaster/LengRe.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using FASTER.core; - -namespace MyFaster -{ - public class LengRe - { - public void AAA() - { - // 创建存储设备(混合内存+磁盘) - var logDevice = Devices.CreateLogDevice("colddata.log"); // 冷数据存储到磁盘 - var logSettings = new LogSettings - { - LogDevice = logDevice, - MemorySizeBits = 20, // 1MB 内存(热数据区) - PageSizeBits = 16 // 64KB 磁盘页 - }; - - // 创建 FASTER 实例 - var store = new FasterKV( - size: 1 << 16, // 哈希表大小 - logSettings: logSettings - ); - - // 创建会话 - var session = store.NewSession(new SimpleFunctions()); - - // 写入数据(自动处理热/冷数据) - Key key = new Key { Id = 1 }; - Value value = new Value { Data = "示例数据", LastAccessed = DateTime.UtcNow }; - - session.Upsert(ref key, ref value); - - // 读取数据(热数据在内存,冷数据从磁盘加载) - Value output = default; - Status status = session.Read(ref key, ref output); - - Console.WriteLine($"读取数据: {output.Data}"); - Console.WriteLine($"最后访问: {output.LastAccessed}"); - - // 更新访问时间(保持数据热度) - output.LastAccessed = DateTime.UtcNow; - session.Upsert(ref key, ref output); - - - - - - - - // 填充测试数据 - for (int i = 0; i < 1000; i++) - { - Key k = new Key { Id = i }; - Value v = new Value { Data = $"Item-{i}", LastAccessed = DateTime.UtcNow }; - session.Upsert(ref k, ref v); - } - - // 访问部分数据保持热度 - for (int i = 0; i < 10; i++) // 频繁访问前10条 - { - Key k = new Key { Id = i }; - Value v = default; - session.Read(ref k, ref v); - v.LastAccessed = DateTime.UtcNow; - session.Upsert(ref k, ref v); - } - - // 此时: - // - 前10条是热数据(在内存) - // - 其余990条是冷数据(在磁盘) - - - - - - } - - public void Read() - { - } - } - public struct Key : IEquatable - { - public int Id; - public bool Equals(Key other) => Id == other.Id; - } - - public struct Value - { - public string Data; - public DateTime LastAccessed; - } -} diff --git a/MyFaster/MyFaster.csproj b/MyFaster/MyFaster.csproj deleted file mode 100644 index 3d5ff05..0000000 --- a/MyFaster/MyFaster.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - Exe - net8.0 - enable - enable - - - - - - - - - - diff --git a/MyFaster/MyFun.cs b/MyFaster/MyFun.cs deleted file mode 100644 index 97eb026..0000000 --- a/MyFaster/MyFun.cs +++ /dev/null @@ -1,98 +0,0 @@ -using FASTER.core; - -// 定义数据结构 -public struct MyKey : IEquatable -{ - public int Id; - public bool Equals(MyKey other) => Id == other.Id; - public override int GetHashCode() => Id.GetHashCode(); -} - -public struct MyValue -{ - public byte[] Data; - public DateTime Timestamp; -} - -public struct MyInput -{ - public byte[] NewData; -} - -public struct MyOutput -{ - public MyValue Value; - public bool Updated; -} - -public struct MyContext -{ - public string OperationId; - public DateTime StartTime; -} - -// 实现自定义 Functions -public class MyCustomFunctions : FunctionsBase -{ - // 读取完成回调 - public override void ReadCompletionCallback(ref MyKey key, ref MyInput input, ref MyOutput output, MyContext ctx, Status status, RecordMetadata recordMetadata) - { - base.ReadCompletionCallback(ref key, ref input, ref output, ctx, status, recordMetadata); - } - - - //// 写入完成回调 - //public override void UpsertCompletionCallback( - // ref MyKey key, ref MyValue value, MyContext ctx) - //{ - // Console.WriteLine($"Upsert completed for key {key.Id}"); - //} - - //// 删除完成回调 - //public override void DeleteCompletionCallback( - // ref MyKey key, MyContext ctx) - //{ - // Console.WriteLine($"Delete completed for key {key.Id}"); - //} - - //// RMW (Read-Modify-Write) 操作 - 核心功能! - //public override void RMWCompletionCallback( - // ref MyKey key, ref MyInput input, ref MyOutput output, - // MyContext ctx, Status status) - //{ - // if (status == Status.OK) - // { - // Console.WriteLine($"RMW completed for key {key.Id}"); - // } - //} - - //// 并发控制:当多个线程同时修改相同键时调用 - //public override bool ConcurrentWriter( - // ref MyKey key, ref MyValue value, ref MyValue newValue) - //{ - // // 返回 true 表示接受新值,false 表示拒绝 - // return newValue.Timestamp > value.Timestamp; - //} - - //// 读取时复制:允许在读取时修改返回值 - //public override bool SingleReader( - // ref MyKey key, ref MyInput input, ref MyValue value, ref MyOutput dst) - //{ - // dst.Value = value; - // dst.Updated = false; - // return true; - //} - - //// 写入时处理:自定义写入逻辑 - //public override bool ConcurrentWriter( - // ref MyKey key, ref MyValue value, ref MyValue newValue) - //{ - // // 只有新数据的时间戳更晚时才更新 - // if (newValue.Timestamp > value.Timestamp) - // { - // value = newValue; - // return true; - // } - // return false; - //} -} diff --git a/MyFaster/Program.cs b/MyFaster/Program.cs deleted file mode 100644 index 1ecec98..0000000 --- a/MyFaster/Program.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System.Diagnostics; -using System.Net; -using FASTER.core; -using MemoryPack; - -namespace MyFaster -{ - [MemoryPackable()] - public partial class MyData - { - public string? FirstName { get; set; } - public string? LastName { get; set; } - public int Age { get; set; } - public string? DetailData { get; set; } - } - internal class Program - { - public static byte[] Serialize(T obj) - { - return MemoryPackSerializer.Serialize(obj); - } - - public static T Deserialize(byte[] data) - { - return MemoryPackSerializer.Deserialize(data); - } - - public class MyValueSerializer1 : BinaryObjectSerializer - { - public override void Serialize(ref MyData value) - { - writer.Write(value.FirstName); - writer.Write(value.LastName); - writer.Write(value.Age); - writer.Write(value.DetailData); - } - - public override void Deserialize(out MyData value) - { - value = new MyData - { - FirstName = reader.ReadString(), - LastName = reader.ReadString(), - Age = reader.ReadInt32(), - DetailData = reader.ReadString() - }; - } - } - - public class MyValueSerializer : BinaryObjectSerializer - { - public override void Serialize(ref MyData value) - { - //writer.Write(IPAddress.HostToNetworkOrder(Q.Length)); // 4字节长度头 - var Q = MemoryPackSerializer.Serialize(value); - writer.Write(Q.Length); // 4字节长度头 - writer.Write(Q); - } - - public override void Deserialize(out MyData value) - { - int length = reader.ReadInt32(); // 读长度头 - byte[] buffer = reader.ReadBytes(length); // 读数据体 - value = MemoryPackSerializer.Deserialize(buffer); // 反序列化 - } - } - - static async Task Main(string[] args) - { - using var settings = new FasterKVSettings() - { - LogDevice = Devices.CreateLogDevice("c:/mytemp/log"), // 元数据日志 - ObjectLogDevice = Devices.CreateLogDevice("c:/mytemp/obj"), // 对象数据日志 - TryRecoverLatest = true, - ValueSerializer = () => new MyValueSerializer() - }; - using var store = new FasterKV(settings); - using var session = store.NewSession(new SimpleFunctions()); - - MyData mydata0 = new MyData() { FirstName = "1", LastName = "fdfdf", DetailData = "detail1" }; - MyData mydata1 = new MyData() { FirstName = "1", LastName = "fdfdf", DetailData = "detail1" }; - MyData mydata2 = new MyData() { FirstName = "1", LastName = "fdfdf", DetailData = "detail1" }; - - string mma0 = "a"; - string mma1 = "b"; - string mma2 = "c"; - - session.Upsert(ref mma0, ref mydata0); - session.Upsert(ref mma1, ref mydata1); - session.Upsert(ref mma2, ref mydata2); - - session.CompletePending(true); - // 创建增量检查点(性能更好) - await store.TakeHybridLogCheckpointAsync(CheckpointType.FoldOver); - - // 方法1:完整检查点(推荐) - await store.TakeFullCheckpointAsync(CheckpointType.Snapshot); - - //完整检查点 - await store.TakeFullCheckpointAsync(CheckpointType.FoldOver); - - MyData output = null; - var status = session.Read(ref mma0, ref output); - - Console.WriteLine("Hello, World!"); - } - } -} diff --git a/MyFunctioncache/MyFunctioncache.csproj b/MyFunctioncache/MyFunctioncache.csproj deleted file mode 100644 index 53030d9..0000000 --- a/MyFunctioncache/MyFunctioncache.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Exe - net8.0 - enable - enable - - - - - - - diff --git a/MyFunctioncache/Program.cs b/MyFunctioncache/Program.cs deleted file mode 100644 index 4a14fd6..0000000 --- a/MyFunctioncache/Program.cs +++ /dev/null @@ -1,41 +0,0 @@ -using ZiggyCreatures.Caching.Fusion; - -namespace MyFunctioncache -{ - internal class Program - { - static void Main(string[] args) - { - var entryOptions = new FusionCacheEntryOptions().SetDuration(TimeSpan.FromMinutes(10)); - - // 创建缓存实例 - var cache = new FusionCache(new FusionCacheOptions() - { - DefaultEntryOptions = new FusionCacheEntryOptions - { - Duration = TimeSpan.FromMinutes(5) // 默认缓存5分钟 - } - }); - // 设置缓存值 - cache.Set("product_123", new PersonInfo {UserName="aaa"}); - - // 获取缓存值 - var product = cache.TryGet("product_123"); - - // 删除缓存项 - cache.Remove("product_123"); - Console.WriteLine("Hello, World!"); - } - } - - public class PersonInfo - { - public string UserName { get; set; } - - public int Age { get; set; } - - public string Nationality { get; set; } - - public string CacheMsg { get; set; } - } -} diff --git a/mypwsh/Program.cs b/mypwsh/Program.cs deleted file mode 100644 index a4b1015..0000000 --- a/mypwsh/Program.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.ObjectModel; -using System.Management.Automation; -using System.Management.Automation.Runspaces; -namespace mypwsh -{ - internal class Program - { - static void Main(string[] args) - { - using (var ps = PowerShell.Create()) - { - // 避免使用 AddScript,改用 AddCommand - ps.AddCommand("Get-Service"); - - var results = ps.Invoke(); - foreach (var result in results) - { - var service = result.BaseObject; - } - } - Console.WriteLine("Hello, World!"); - } - } -} diff --git a/mypwsh/mypwsh.csproj b/mypwsh/mypwsh.csproj deleted file mode 100644 index 94d3d43..0000000 --- a/mypwsh/mypwsh.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - Exe - net8.0-windows - enable - enable - - - - - - - -