简体   繁体   中英

Checking for a break while moving SQL storage

I have already completed this job, but wondering whether what I did was correct and / or whether you would have performed the job differently.

A couple of the infrastructure guys came to me saying that they were moving the storage for one of the SQL servers and they wanted to check whether there was any break in connection or performance while they were doing it - they had some company in that said they could move the storage without having any impact on the business and this is the first try.

To test this out, they wanted me to write a query that would use the storage and report any breaks, so I wrote the following script ad hoc:

CREATE TABLE [dbo].[TomAndRickysSpecialTable]
( [Counter] INT IDENTITY(1,1) NOT NULL
 ,[Result]  VARCHAR(10)     NOT NULL
 ,[TimeStamp] DATETIME2(0) NOT NULL DEFAULT(GETDATE())
,CONSTRAINT PK_TikkiTavi PRIMARY KEY CLUSTERED ([counter] ASC)
)
exec sp_configure 'remote query timeout', 0 
go 
reconfigure with override 
go

CREATE PROC RICKYRICKYRICKYRICKYrickyTom
AS
    TRUNCATE TABLE TomAndRickysSpecialTable;
    INSERT TomAndRickysSpecialTable(Result) VALUES ('Start');
    SET NOCOUNT ON;
    TryAgain:
    WHILE 1 = 1
    BEGIN
    BEGIN TRY
        WAITFOR DELAY '00:00:01';
        IF EXISTS (SELECT TOP 1 [Counter] FROM TomAndRickysSpecialTable)
            INSERT TomAndRickysSpecialTable(Result) VALUES ('Yup');
            RAISERROR('Yup',10,1) WITH NOWAIT;  
    END TRY
    BEGIN CATCH
        RAISERROR('Nop',10,1) WITH NOWAIT;
        Goto TryAgain;
    END CATCH
    END

I created the table and sproc and they executed it from the server, leaving it to run and observing any breaks in the second by second timestamp.

I figured I should write something that queried and wrote to the memory, so that we could see if there was a problem, but I have no idea whether that reasoning was correct...

My question is this - would my script have actually done what they wanted? Was there any point in running it or would it for instance have failed so badly if there was a break that there was no reportable result? Could I have written a simpler or better script to do the same job?

PS. I hated writing the While loop and the goto, but figured it would do the job in this weird case!

would my script have actually done what they wanted?

Yes. SQL Server caches data in memory, but changes must be hardened to disk on commit, and by default SQL Server commits after each statement. So the INSERT would have failed if the disk containing the database log was unavailable.

BTW 'remote query timeout' is irrelevant.

I hated writing the While loop and the goto,

It's not needed. After the CATCH block the WHILE loop would have run again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM