June 4, 2012

sp_MSupdatecachedpeerlsn (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_MSupdatecachedpeerlsn(int @type
, int @agent_id
, nvarchar @originator
, nvarchar @originator_db
, int @originator_publication_id
, int @originator_db_version
, varbinary @originator_lsn)

MetaData:

 create procedure sys.sp_MSupdatecachedpeerlsn  
(
@type int, -- 1-insert/update, 2-clear
@agent_id int,
@originator sysname = NULL,
@originator_db sysname = NULL,
@originator_publication_id int = NULL,
@originator_db_version int = NULL,
@originator_lsn varbinary(16) = NULL
)
as
begin
declare @retcode bit

-- security check - the distribution agent must have access
exec @retcode = sys.sp_MScheck_pull_access @agent_id = @agent_id, @agent_type = 0
if @@error <> 0 or @retcode <> 0
begin
return 1
end

if @type not in (0, 1, 2)
begin
-- Invalid '@type' value for stored procedure 'sys.sp_MSupdatecachedpeerlsn'.
raiserror(20587, 16, -1, '@type', 'sys.sp_MSupdatecachedpeerlsn')
return 1
end

begin tran t_MScached_peer_lsns

-- insert/update row
if @type = 1
begin
update MScached_peer_lsns
set originator_lsn = @originator_lsn
where agent_id = @agent_id
and UPPER(originator) = UPPER(@originator)
and originator_db = @originator_db
and originator_publication_id = @originator_publication_id
and originator_db_version = @originator_db_version
if @@rowcount < 1
begin
insert into MScached_peer_lsns
(
agent_id,
originator,
originator_db,
originator_publication_id,
originator_db_version,
originator_lsn
)
values
(
@agent_id,
UPPER(@originator),
@originator_db,
@originator_publication_id,
@originator_db_version,
@originator_lsn
)
if @@rowcount < 1 or @@error <> 0
goto FAILURE
end

if @@error <> 0
begin
-- The distribution agent was unable to update the cached lsns for Originator:%s OriginatorDB:%s OriginatorDBVersion:%d OriginatorPublicationID:%d.
raiserror(21680, 16, -1, @originator, @originator_db, @originator_db_version, @originator_publication_id)
goto FAILURE
end
end
-- clear cache for the specified agent
else if @type = 2
begin
delete from MScached_peer_lsns
where agent_id = @agent_id
if @@error <> 0
goto FAILURE
end

commit transaction t_MScached_peer_lsns

return 0
FAILURE:
if @@trancount > 0
rollback transaction t_MScached_peer_lsns

-- The procedure sys.sp_MSupdatecachedpeerlsn failed to UPDATE the resource MScached_peer_lsns Server error = 21499.
raiserror (21499, 16, -1, 'sys.sp_MSupdatecachedpeerlsn', 'UPDATE', 'MScached_peer_lsns', @@error)
return 1
end

No comments:

Post a Comment

Total Pageviews