Пример #1
0
            public void Initialize(string checkpointDirectory, string logDirectory, bool populateLogHandles = false)
            {
#if NETCOREAPP || NET
                if (!RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
                {
                    populateLogHandles = false;
                }
#endif
                this.CheckpointDirectory = checkpointDirectory;
                this.LogDirectory        = logDirectory;

                string logFileName    = "log";
                string deviceFileName = $"{this.LogDirectory}/{logFileName}";
                KeyValuePair <int, SafeFileHandle>[] initialHandles = null;
                if (populateLogHandles)
                {
                    var segmentIds = new List <int>();
                    foreach (FileInfo item in new DirectoryInfo(logDirectory).GetFiles(logFileName + "*"))
                    {
                        segmentIds.Add(int.Parse(item.Name.Replace(logFileName, "").Replace(".", "")));
                    }
                    segmentIds.Sort();
                    initialHandles = new KeyValuePair <int, SafeFileHandle> [segmentIds.Count];
                    for (int i = 0; i < segmentIds.Count; i++)
                    {
                        var segmentId = segmentIds[i];
#pragma warning disable CA1416 // populateLogHandles will be false for non-windows
                        var handle = LocalStorageDevice.CreateHandle(segmentId, disableFileBuffering: false, deleteOnClose: true, preallocateFile: false, segmentSize: -1, fileName: deviceFileName, IntPtr.Zero);
#pragma warning restore CA1416
                        initialHandles[i] = new KeyValuePair <int, SafeFileHandle>(segmentId, handle);
                    }
                }

#if NETCOREAPP || NET
                if (!RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
                {
                    this.LogDevice = new ManagedLocalStorageDevice(deviceFileName, deleteOnClose: true);
                }
                else
#endif
                {
                    this.LogDevice = new LocalStorageDevice(deviceFileName, deleteOnClose: true, disableFileBuffering: false, initialLogFileHandles: initialHandles);
                }

                this.Faster = new FasterKV <AdId, NumClicks>(
                    keySpace,
                    new LogSettings {
                    LogDevice = this.LogDevice
                },
                    new CheckpointSettings {
                    CheckpointDir = this.CheckpointDirectory, CheckPointType = CheckpointType.FoldOver
                });
            }
Пример #2
0
            public void Initialize(string checkpointDirectory, string logDirectory, bool populateLogHandles = false)
            {
                this.CheckpointDirectory = checkpointDirectory;
                this.LogDirectory        = logDirectory;

                string logFileName    = "log";
                string deviceFileName = $"{this.LogDirectory}\\{logFileName}";

                KeyValuePair <int, SafeFileHandle>[] initialHandles = null;
                if (populateLogHandles)
                {
                    var segmentIds = new List <int>();
                    foreach (FileInfo item in new DirectoryInfo(logDirectory).GetFiles(logFileName + "*"))
                    {
                        segmentIds.Add(int.Parse(item.Name.Replace(logFileName, "").Replace(".", "")));
                    }
                    segmentIds.Sort();
                    initialHandles = new KeyValuePair <int, SafeFileHandle> [segmentIds.Count];
                    for (int i = 0; i < segmentIds.Count; i++)
                    {
                        var segmentId = segmentIds[i];
                        var handle    = LocalStorageDevice.CreateHandle(segmentId, disableFileBuffering: false, deleteOnClose: true, preallocateFile: false, segmentSize: -1, fileName: deviceFileName);
                        initialHandles[i] = new KeyValuePair <int, SafeFileHandle>(segmentId, handle);
                    }
                }

                this.LogDevice = new LocalStorageDevice(deviceFileName, deleteOnClose: true, disableFileBuffering: false, initialLogFileHandles: initialHandles);
                this.Faster    = new FasterKV <AdId, NumClicks, AdInput, Output, Empty, Functions>(
                    keySpace,
                    new Functions(),
                    new LogSettings {
                    LogDevice = this.LogDevice
                },
                    new CheckpointSettings {
                    CheckpointDir = this.CheckpointDirectory, CheckPointType = CheckpointType.FoldOver
                });
            }