Example #1
0
 public Type1Partition(UdfContext context, LogicalVolumeDescriptor volumeDescriptor,
                       Type1PartitionMap partitionMap)
     : base(context, volumeDescriptor)
 {
     _partitionMap = partitionMap;
     _physical     = context.PhysicalPartitions[partitionMap.PartitionNumber];
 }
Example #2
0
        public void CreateStgTable()
        {
            // Create the new table in the appropriate filegroup for the SWITCH
            foreach (Column c in partitionTable.Columns)
            {
                // Populate the table with each column and associated properties from the partition table
                Column stgCol = new Column(stgTable, c.Name, c.DataType);
                stgCol.Collation    = c.Collation;
                stgCol.Nullable     = c.Nullable;
                stgCol.Computed     = c.Computed;
                stgCol.ComputedText = c.ComputedText;
                stgCol.Default      = c.Default;
                // Apply default constraint value, if present, as a default value
                if (c.DefaultConstraint != null)
                {
                    stgCol.AddDefaultConstraint(stgTable.Name + "_" + c.DefaultConstraint.Name);
                    stgCol.DefaultConstraint.Text = c.DefaultConstraint.Text;
                }
                stgCol.IsPersisted   = c.IsPersisted;
                stgCol.DefaultSchema = c.DefaultSchema;
                stgCol.RowGuidCol    = c.RowGuidCol;
                if (srv.VersionMajor >= 10)
                {
                    stgCol.IsFileStream = c.IsFileStream;
                    stgCol.IsSparse     = c.IsSparse;
                    stgCol.IsColumnSet  = c.IsColumnSet;
                }
                stgTable.Columns.Add(stgCol);
            }
            // Match other new table attributes to the partition table; required for SWITCH compatibility
            stgTable.AnsiNullsStatus        = partitionTable.AnsiNullsStatus;
            stgTable.QuotedIdentifierStatus = partitionTable.QuotedIdentifierStatus;
            // Calculate the filegroup associated with the partition nunber to switch; create temp table in that filegroup
            stgTable.FileGroup     = db.PartitionSchemes[partitionTable.PartitionScheme].FileGroups[partitionNumber - 1];
            stgTable.TextFileGroup = db.PartitionSchemes[partitionTable.PartitionScheme].FileGroups[partitionNumber - 1];

            if (srv.VersionMajor >= 10)
            {
                // Define compression property to match by creating a Physical Partition object
                PhysicalPartition stgPartition = new PhysicalPartition(stgTable, 1, partitionTable.PhysicalPartitions[partitionNumber - 1].DataCompression);
                stgTable.PhysicalPartitions.Add(stgPartition);
            }
            scriptChunks.Add(stgTable.Script());
            if (executeCommands)
            {
                stgTable.Create();
            }
        }
Example #3
0
        private void createStgIndex(Index i, TableViewBase parent)
        {
            if (i.PartitionScheme == "")
            {
                throw (new System.NotSupportedException(
                           String.Format("The index '{0}' is not aligned to a Partition Scheme", i.Name)));
            }

            // todo:  differentiate between Base Table as source, and View as source

            // LZAV:  Index stgIndex = new Index(parent, parent.Name + "_" + i.Name);
            String indexName = parent.Name + "_" + i.Name;                      // LZAV

            if (indexName.Length > 128)                                         // LZAV
            {
                indexName = "IX_CL_" + parent.Name;                             // LZAV
            }
            Index stgIndex = new Index(parent, indexName);                      // LZAV

            foreach (IndexedColumn iCol in i.IndexedColumns)
            {
                IndexedColumn stgICol = new IndexedColumn(stgIndex, iCol.Name, iCol.Descending);
                stgICol.IsIncluded = iCol.IsIncluded;
                stgIndex.IndexedColumns.Add(stgICol);
            }
            stgIndex.IndexType           = i.IndexType;
            stgIndex.IndexKeyType        = i.IndexKeyType;
            stgIndex.IsClustered         = i.IsClustered;
            stgIndex.IsUnique            = i.IsUnique;
            stgIndex.CompactLargeObjects = i.CompactLargeObjects;
            stgIndex.IgnoreDuplicateKeys = i.IgnoreDuplicateKeys;
            stgIndex.IsFullTextKey       = i.IsFullTextKey;
            stgIndex.PadIndex            = i.PadIndex;
            stgIndex.FileGroup           = db.PartitionSchemes[i.PartitionScheme].FileGroups[partitionNumber - 1];

            // add the partitioning column to the index if it is not already there
            String partitionKeyName = i.PartitionSchemeParameters[0].Name;

            if (stgIndex.IndexedColumns[partitionKeyName] == null)
            {
                IndexedColumn stgICol = new IndexedColumn(stgIndex, partitionKeyName);
                // It is added as a Key to the Clustered index and as an Include column to a Nonclustered
                stgICol.IsIncluded = !stgIndex.IsClustered;
                stgIndex.IndexedColumns.Add(stgICol);
            }

            if (srv.VersionMajor >= 10)
            {
                // Define compression property to match by creating a Physical Partition object (not applicable to Colstore)
                {
                    PhysicalPartition stgPartition = new PhysicalPartition(stgIndex, 1);
                    if (i.IndexType != IndexType.NonClusteredColumnStoreIndex)
                    {
                        stgPartition.DataCompression = i.PhysicalPartitions[partitionNumber - 1].DataCompression;
                    }
                    stgIndex.PhysicalPartitions.Add(stgPartition);
                }
                // Handle Filtered Index
                if (i.HasFilter)
                {
                    stgIndex.FilterDefinition = i.FilterDefinition;
                }
            }
            scriptChunks.Add(stgIndex.Script());
            if (executeCommands)
            {
                stgIndex.Create();
            }
        }
Example #4
0
 public Type1Partition(UdfContext context, LogicalVolumeDescriptor volumeDescriptor, Type1PartitionMap partitionMap)
     : base(context, volumeDescriptor)
 {
     _partitionMap = partitionMap;
     _physical = context.PhysicalPartitions[partitionMap.PartitionNumber];
 }
        public List <PhysicalPartition> GetActivePartitions(int schemaHdNumber, ImageProfileWithImage imageProfile)
        {
            var listPhysicalPartition = new List <PhysicalPartition>();

            foreach (
                var partition in _imageSchema.HardDrives[schemaHdNumber].Partitions.Where(partition => partition.Active)
                )
            {
                var physicalPartition = new PhysicalPartition();
                physicalPartition.Number        = partition.Number;
                physicalPartition.Guid          = partition.Guid;
                physicalPartition.Uuid          = partition.Uuid;
                physicalPartition.FileSystem    = partition.FsType;
                physicalPartition.Type          = partition.Type;
                physicalPartition.EfiBootLoader = partition.EfiBootLoader;
                string imageFile = null;
                foreach (var ext in new[] { "ntfs", "fat", "extfs", "hfsp", "imager", "xfs" })
                {
                    imageFile = new FilesystemServices().GetFileNameWithFullPath(imageProfile.Image.Name,
                                                                                 schemaHdNumber.ToString(), partition.Number, ext);

                    if (!string.IsNullOrEmpty(imageFile))
                    {
                        physicalPartition.PartcloneFileSystem = ext;
                        break;
                    }
                }
                switch (Path.GetExtension(imageFile))
                {
                case ".lz4":
                    physicalPartition.Compression = "lz4";
                    physicalPartition.ImageType   = "Block";
                    break;

                case ".gz":
                    physicalPartition.Compression = "gz";
                    physicalPartition.ImageType   = "Block";
                    break;

                case ".uncp":
                    physicalPartition.Compression = "uncp";
                    physicalPartition.ImageType   = "Block";
                    break;

                case ".wim":
                    physicalPartition.ImageType = "File";
                    break;
                }

                if (partition.VolumeGroup.Name != null)
                {
                    physicalPartition.VolumeGroup      = new VolumeGroup();
                    physicalPartition.VolumeGroup.Name = partition.VolumeGroup.Name;
                    var listLogicalVolumes   = new List <CloneDeploy_Entities.DTOs.ClientImaging.LogicalVolume>();
                    var logicalVolumeCounter = 0;
                    foreach (var logicalVolume in partition.VolumeGroup.LogicalVolumes.Where(x => x.Active))
                    {
                        logicalVolumeCounter++;
                        var clientLogicalVolume = new CloneDeploy_Entities.DTOs.ClientImaging.LogicalVolume();
                        clientLogicalVolume.Name       = logicalVolume.Name;
                        clientLogicalVolume.FileSystem = logicalVolume.FsType;
                        clientLogicalVolume.Uuid       = logicalVolume.Uuid;

                        foreach (var ext in new[] { "ntfs", "fat", "extfs", "hfsp", "imager", "xfs" })
                        {
                            imageFile = new FilesystemServices().GetLVMFileNameWithFullPath(imageProfile.Image.Name,
                                                                                            schemaHdNumber.ToString(), partition.VolumeGroup.Name, logicalVolume.Name, ext);

                            if (!string.IsNullOrEmpty(imageFile))
                            {
                                clientLogicalVolume.PartcloneFileSystem = ext;
                                break;
                            }
                        }
                        switch (Path.GetExtension(imageFile))
                        {
                        case ".lz4":
                            clientLogicalVolume.Compression = "lz4";
                            clientLogicalVolume.ImageType   = "Block";
                            break;

                        case ".gz":
                            clientLogicalVolume.Compression = "gz";
                            clientLogicalVolume.ImageType   = "Block";
                            break;

                        case ".uncp":
                            clientLogicalVolume.Compression = "uncp";
                            clientLogicalVolume.ImageType   = "Block";
                            break;

                        case ".wim":
                            clientLogicalVolume.ImageType = "File";
                            break;
                        }

                        listLogicalVolumes.Add(clientLogicalVolume);
                    }
                    physicalPartition.VolumeGroup.LogicalVolumeCount = logicalVolumeCounter;
                    physicalPartition.VolumeGroup.LogicalVolumes     = listLogicalVolumes;
                }
                listPhysicalPartition.Add(physicalPartition);
            }

            return(listPhysicalPartition);
        }
        private void createStgIndex(Index i, TableViewBase parent)
        {
            if (i.PartitionScheme == "")
                throw (new System.NotSupportedException(
                    String.Format("The index '{0}' is not aligned to a Partition Scheme", i.Name)));

              // todo:  differentiate between Base Table as source, and View as source

              // LZAV:  Index stgIndex = new Index(parent, parent.Name + "_" + i.Name);
              String indexName = parent.Name + "_" + i.Name;		// LZAV
              if (indexName.Length > 128)						// LZAV
              indexName = "IX_CL_" + parent.Name;				// LZAV

              Index stgIndex = new Index(parent, indexName);		// LZAV

              foreach (IndexedColumn iCol in i.IndexedColumns)
              {
             IndexedColumn stgICol = new IndexedColumn(stgIndex, iCol.Name, iCol.Descending);
             stgICol.IsIncluded = iCol.IsIncluded;
             stgIndex.IndexedColumns.Add(stgICol);
              }
              stgIndex.IndexType = i.IndexType;
              stgIndex.IndexKeyType = i.IndexKeyType;
              stgIndex.IsClustered = i.IsClustered;
              stgIndex.IsUnique = i.IsUnique;
              stgIndex.CompactLargeObjects = i.CompactLargeObjects;
              stgIndex.IgnoreDuplicateKeys = i.IgnoreDuplicateKeys;
              stgIndex.IsFullTextKey = i.IsFullTextKey;
              stgIndex.PadIndex = i.PadIndex;
              stgIndex.FileGroup = db.PartitionSchemes[i.PartitionScheme].FileGroups[partitionNumber - 1];

              // add the partitioning column to the index if it is not already there
              String partitionKeyName = i.PartitionSchemeParameters[0].Name;
              if (stgIndex.IndexedColumns[partitionKeyName] == null)
              {
             IndexedColumn stgICol = new IndexedColumn(stgIndex, partitionKeyName);
             // It is added as a Key to the Clustered index and as an Include column to a Nonclustered
             stgICol.IsIncluded = !stgIndex.IsClustered;
             stgIndex.IndexedColumns.Add(stgICol);
              }

              if (srv.VersionMajor >= 10)
              {
             // Define compression property to match by creating a Physical Partition object (not applicable to Colstore)
             {
                PhysicalPartition stgPartition = new PhysicalPartition(stgIndex, 1);
                if (i.IndexType != IndexType.NonClusteredColumnStoreIndex)
                {
                    stgPartition.DataCompression = i.PhysicalPartitions[partitionNumber - 1].DataCompression;
                }
                stgIndex.PhysicalPartitions.Add(stgPartition);
             }
             // Handle Filtered Index
             if (i.HasFilter)
             {
                stgIndex.FilterDefinition = i.FilterDefinition;
             }
              }
              scriptChunks.Add(stgIndex.Script());
              if (executeCommands) stgIndex.Create();
        }
        public void CreateStgTable()
        {
            // Create the new table in the appropriate filegroup for the SWITCH
              foreach (Column c in partitionTable.Columns)
              {
             // Populate the table with each column and associated properties from the partition table
             Column stgCol = new Column(stgTable, c.Name, c.DataType);
             stgCol.Collation = c.Collation;
             stgCol.Nullable = c.Nullable;
             stgCol.Computed = c.Computed;
             stgCol.ComputedText = c.ComputedText;
             stgCol.Default = c.Default;
             // Apply default constraint value, if present, as a default value
             if (c.DefaultConstraint != null)
             {
                stgCol.AddDefaultConstraint(stgTable.Name + "_" + c.DefaultConstraint.Name);
                stgCol.DefaultConstraint.Text = c.DefaultConstraint.Text;
             }
             stgCol.IsPersisted = c.IsPersisted;
             stgCol.DefaultSchema = c.DefaultSchema;
             stgCol.RowGuidCol = c.RowGuidCol;
             if (srv.VersionMajor >= 10)
             {
                stgCol.IsFileStream = c.IsFileStream;
                stgCol.IsSparse = c.IsSparse;
                stgCol.IsColumnSet = c.IsColumnSet;
             }
             stgTable.Columns.Add(stgCol);
              }
              // Match other new table attributes to the partition table; required for SWITCH compatibility
              stgTable.AnsiNullsStatus = partitionTable.AnsiNullsStatus;
              stgTable.QuotedIdentifierStatus = partitionTable.QuotedIdentifierStatus;
              // Calculate the filegroup associated with the partition nunber to switch; create temp table in that filegroup
              stgTable.FileGroup = db.PartitionSchemes[partitionTable.PartitionScheme].FileGroups[partitionNumber - 1];
              stgTable.TextFileGroup = db.PartitionSchemes[partitionTable.PartitionScheme].FileGroups[partitionNumber - 1];

              if (srv.VersionMajor >= 10)
              {
             // Define compression property to match by creating a Physical Partition object
             PhysicalPartition stgPartition = new PhysicalPartition(stgTable, 1, partitionTable.PhysicalPartitions[partitionNumber - 1].DataCompression);
             stgTable.PhysicalPartitions.Add(stgPartition);
              }
              scriptChunks.Add(stgTable.Script());
              if (executeCommands) stgTable.Create();
        }