May 24, 2012

sp_MSrecordsnapshotdeliveryprogress (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_MSrecordsnapshotdeliveryprogress(nvarchar @snapshot_session_token
, nvarchar @snapshot_progress_token)

MetaData:

 --   
-- Name: sp_MSrecordsnapshotdeliveryprogress
--
-- Description: This procedure is used by the distribution agent or the merge
-- agent to record a snapshot delivery work item that has been
-- applied to a subscriber database in the
-- MSsnapshotdeliveryprogress table. In the event of restarting
-- an interrupted snapshot delivery process, the distribution or
-- merge agent can use the information stored in the
-- MSsnapshotdeliveryprogress table to avoid redoing snapshot
-- delivery processing that has already been applied to the
-- subscriber.
--
-- Note: This procedure should only be called by the distribution agent or
-- the merge agent at the subscriber database.
--
-- Parameters: @snapshot_session_token nvarchar(260) (mandatory)
-- - a UniCode string that uniquely identifies a snapshot
-- delivery session. For now, this will be a the full folder
-- path of the particular snapshot being applied (hence the
-- 260 characters size).
-- @snapshot_progress_token nvarchar(500) (mandatory)
-- - A unicode string that uniquely identifies a snapshot work
-- item (schema creation, bulk-loading data) that has been
-- applied to the subscriber.
--
-- Returns: 0 - succeeded
-- 1 - failed
--
-- Security: Execute permission of this procedure is granted to public;
-- procedural security check will be performed to make sure
-- that the caller is either a db_owner of the current database
-- or a sysadmin.
--
create procedure sys.sp_MSrecordsnapshotdeliveryprogress (
@snapshot_session_token nvarchar(260),
@snapshot_progress_token nvarchar(500)
)
as
begin
set nocount on
set arithabort on
declare @retcode int
declare @snapshot_progress_token_hash int
select @retcode = 0

exec @retcode = sys.sp_MSreplcheck_subscribe
if @retcode <> 0 or @@error <> 0
begin
select @retcode = 1
goto FAILURE
end

if object_id('dbo.MSsnapshotdeliveryprogress') is null
begin
create table dbo.MSsnapshotdeliveryprogress
(
session_token nvarchar(260) not null,
progress_token_hash int not null,
progress_token nvarchar(500) not null,
progress_timestamp datetime default getdate()
)
if @@ERROR <> 0
begin
select @retcode = 1
goto FAILURE
end
create index ci_MSsnapshotdeliveryprogress_progress_token_hash
on dbo.MSsnapshotdeliveryprogress(progress_token_hash)
if @@ERROR <> 0
begin
select @retcode = 1
goto FAILURE
end
create index nci_MSsnapshotdeliveryprogress_session_token
on dbo.MSsnapshotdeliveryprogress(session_token)
if @@ERROR <> 0
begin
select @retcode = 1
goto FAILURE
end
exec @retcode = dbo.sp_MS_marksystemobject 'dbo.MSsnapshotdeliveryprogress'
if @retcode <> 0 or @@ERROR <> 0
begin
select @retcode = 1
goto FAILURE
end
end

select @snapshot_progress_token_hash = sys.fn_repl32bitstringhash(@snapshot_progress_token)
if @retcode <> 0 or @@ERROR <> 0
begin
select @retcode = 1
goto FAILURE
end

if exists (select * from MSsnapshotdeliveryprogress
where progress_token_hash = @snapshot_progress_token_hash
and progress_token = @snapshot_progress_token
and session_token = @snapshot_session_token)
begin
update MSsnapshotdeliveryprogress
set progress_timestamp = getdate()
where progress_token = @snapshot_progress_token
and session_token = @snapshot_session_token
if @@ERROR <> 0
begin
select @retcode = 1
goto FAILURE
end
end
else
begin
insert MSsnapshotdeliveryprogress
values (
@snapshot_session_token,
@snapshot_progress_token_hash,
@snapshot_progress_token,
default)
if @@ERROR <> 0
begin
select @retcode = 1
goto FAILURE
end
end
if @@ERROR <> 0
begin
select @retcode = 1
goto FAILURE
end

FAILURE:
return @retcode
end

No comments:

Post a Comment

Total Pageviews