The conversion between 10 and 16 of the LSN

Source: Internet
Author: User

The conversion between 10 and 16 of the LSN

First, 16 into the system

LSN, which is the log sequence number, is divided into 3 paragraphs in 16-Sequence, in the form of:

FSeqNo:SectorNo:SlotNo

The meanings are:

1 1th: Fseqno is the serial number of the virtual log file (VLF) with a length of 4 bytes.

2) Sectorno is the number of sectors in the VLF and the length is 4 bytes.

3) Slotno is the number of sectors in which the log is located, and the length is 2 bytes.

Two, 10 in the system

The LSN type in 10 is numeric (25,0), which is also divided into three segments, respectively:

1) from 0-4 bits (total 5 digits) for Slotno

2) from 5-14 bits (total 10 digits) for Sectorno

3) from 15-24 bits (total 10 digits) for fseqno

When the number of partial digits is insufficient, the left side is padded with 0 (Fseqno does not need to be padded and padded).

Iii. examples

For more information about the conversion between 10 and 16, please refer to the blog: "Switch between MS SQL Server10 and 16"

DECLARE @LSN16 VARCHAR (50)

DECLARE @LSN10 NUMERIC (25, 0)

DECLARE @LSN VARCHAR (25)

Set @LSN16 = ' 00000021:00000120:0001 '

SELECT @LSN10 = Convert (INT, convert (VARBINARY, ' 0X ' + SUBSTRING (@LSN16, 1, 8), 1)) * 1000000000000000

+ CONVERT (INT, convert (VARBINARY, ' 0X ' + SUBSTRING (@LSN16, 10, 8), 1)) * 100000

+ CONVERT (INT, convert (VARBINARY, ' 0X ' + SUBSTRING (@LSN16, 19, 4), 1))

SELECT @LSN10

SELECT @LSN = right (' 0000000000 ' + CONVERT (VARCHAR, @LSN10), 25)

SELECT CONVERT (VARCHAR), convert (VARBINARY, convert (INT, SUBSTRING (@LSN, 1, 10)), 2) + ': '

+ CONVERT (VARCHAR), convert (VARBINARY, convert (INT, SUBSTRING (@LSN, 11, 10)), 2) + ': '

+ CONVERT (VARCHAR), convert (VARBINARY, convert (INT, SUBSTRING (@LSN, 21, 5)), 2)

--Return

--33000000028800001

--00000021:00000120:00000001

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.