/// <summary>
 /// Check the version of the CnC file is compatible with application.
 /// </summary>
 /// <param name="cncVersion"> of the CnC file. </param>
 /// <exception cref="AeronException"> if the major versions are not compatible. </exception>
 public static void CheckVersion(int cncVersion)
 {
     if (SemanticVersion.Major(CNC_VERSION) != SemanticVersion.Major(cncVersion))
     {
         throw new AeronException("CnC version not compatible:" + " app=" + SemanticVersion.ToString(CNC_VERSION) + " file=" + SemanticVersion.ToString(cncVersion));
     }
 }
Exemple #2
0
        public ClusterMarkFile(DirectoryInfo directory, string filename, IEpochClock epochClock, long timeoutMs,
                               Action <string> logger)
        {
            markFile = new MarkFile(
                directory,
                filename,
                MarkFileHeaderDecoder.VersionEncodingOffset(),
                MarkFileHeaderDecoder.ActivityTimestampEncodingOffset(),
                timeoutMs,
                epochClock,
                (version) =>
            {
                if (SemanticVersion.Major(version) != AeronCluster.Configuration.MAJOR_VERSION)
                {
                    throw new ArgumentException("mark file major version " + SemanticVersion.Major(version) +
                                                " does not match software:" + AeronCluster.Configuration.MAJOR_VERSION);
                }
            },
                logger);

            buffer = markFile.Buffer();
            headerDecoder.Wrap(buffer, 0, MarkFileHeaderDecoder.BLOCK_LENGTH, MarkFileHeaderDecoder.SCHEMA_VERSION);
            errorBuffer = new UnsafeBuffer(buffer, headerDecoder.HeaderLength(), headerDecoder.ErrorBufferLength());
        }
Exemple #3
0
        public ClusterMarkFile(
            FileInfo file,
            ClusterComponentType type,
            int errorBufferLength,
            IEpochClock epochClock,
            long timeoutMs)
        {
            var markFileExists = file.Exists;

            markFile = new MarkFile(
                file,
                markFileExists,
                MarkFileHeaderDecoder.VersionEncodingOffset(),
                MarkFileHeaderDecoder.ActivityTimestampEncodingOffset(),
                HEADER_LENGTH + errorBufferLength,
                timeoutMs,
                epochClock,
                (version) =>
            {
                if (VERSION_FAILED == version && markFileExists)
                {
                    Console.WriteLine("mark file version -1 indicates error on previous startup.");
                }
                else if (SemanticVersion.Major(version) != AeronCluster.Configuration.MAJOR_VERSION)
                {
                    throw new ArgumentException("mark file major version " + SemanticVersion.Major(version) +
                                                " does not match software:" + AeronCluster.Configuration.MAJOR_VERSION);
                }
            },
                null);

            buffer      = markFile.Buffer();
            errorBuffer = new UnsafeBuffer(buffer, HEADER_LENGTH, errorBufferLength);


            headerEncoder.Wrap(buffer, 0);
            headerDecoder.Wrap(buffer, 0, MarkFileHeaderDecoder.BLOCK_LENGTH, MarkFileHeaderDecoder.SCHEMA_VERSION);

            if (markFileExists)
            {
                var existingErrorBuffer = new UnsafeBuffer(
                    buffer, headerDecoder.HeaderLength(), headerDecoder.ErrorBufferLength());

                SaveExistingErrors(file, existingErrorBuffer, Console.Error);

                errorBuffer.SetMemory(0, errorBufferLength, 0);
            }
            else
            {
                headerEncoder.CandidateTermId(Aeron.Aeron.NULL_VALUE);
            }

            var existingType = headerDecoder.ComponentType();

            if (existingType != ClusterComponentType.NULL && existingType != type)
            {
                if (existingType != ClusterComponentType.BACKUP || ClusterComponentType.CONSENSUS_MODULE != type)
                {
                    throw new InvalidOperationException(
                              "existing Mark file type " + existingType + " not same as required type " + type);
                }
            }

            headerEncoder.ComponentType(type);
            headerEncoder.HeaderLength(HEADER_LENGTH);
            headerEncoder.ErrorBufferLength(errorBufferLength);
            headerEncoder.Pid(Process.GetCurrentProcess().Id);
            headerEncoder.StartTimestamp(epochClock.Time());
        }