May 24, 2012

sp_MSrefresh_publisher_idrange (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_MSrefresh_publisher_idrange(nvarchar @qualified_object_name
, uniqueidentifier @subid
, uniqueidentifier @artid
, tinyint @ranges_needed
, bit @refresh_check_constraint)

MetaData:

 --  this proc will refresh the local publisher's range  
create procedure sys.sp_MSrefresh_publisher_idrange
@qualified_object_name nvarchar(517),
@subid uniqueidentifier, -- pubid of the publisher whose range is to be refreshed.
@artid uniqueidentifier, -- though the artid can be derived from the @qualified_object_name, we will take it as a parameter to do one less query
@ranges_needed tinyint, -- 0=none needed, 1=one range needed, 2=both ranges needed
@refresh_check_constraint bit
as
declare @range_begin numeric(38,0)
declare @range_end numeric(38,0)
declare @next_range_begin numeric(38,0)
declare @next_range_end numeric(38,0)
declare @retcode int

exec @retcode = sys.sp_MSreplcheck_publish
if @@error<>0 or @retcode<>0
return 1

if @ranges_needed=0
return 0

if @artid is NULL
begin
select @artid=artid from dbo.sysmergearticles where objid=object_id(@qualified_object_name)
if @artid is NULL
begin
RAISERROR (20027, 16, -1, @qualified_object_name)
RETURN (1)
end
end

select @range_begin = range_begin,
@range_end = range_end,
@next_range_begin = next_range_begin,
@next_range_end = next_range_end
from dbo.MSmerge_identity_range where artid=@artid and subid=@subid and is_pub_range=0

exec @retcode = sys.sp_MSget_new_idrange
@qualified_object_name,
@artid,
@range_begin output,
@range_end output,
@next_range_begin output,
@next_range_end output,
2, -- subscriber range. This is the publisher's local range.
@ranges_needed
if @@error<>0 or @retcode<>0
begin
raiserror(21197, 16, -1)
return 1
end

if @refresh_check_constraint=1 and @qualified_object_name is not NULL
begin
exec @retcode = sys.sp_MSrefresh_idrange_check_constraint @qualified_object_name, @artid, @range_begin, @range_end, @next_range_begin, @next_range_end, @ranges_needed
if @@error<>0 or @retcode<>0
begin
raiserror(21197, 16, -1)
return 1
end
end

update dbo.MSmerge_identity_range
set range_begin = @range_begin,
range_end = @range_end,
next_range_begin = @next_range_begin,
next_range_end = @next_range_end
where subid=@subid and artid=@artid and is_pub_range=0
if @@ERROR<>0
begin
raiserror(21197, 16, -1)
return 1
end

-- also update on the distributor the identity range that was just allocated to the publisher
-- we will do this only for the root publisher. When a republisher gets restored from backup
-- it should merge with its root publisher to get the information on what ranges were allocated.
exec @retcode = sys.sp_MSmerge_log_idrange_alloc_on_distributor
@subid,
@artid,
0, -- is_pub_range 0 because in Yukon publisher's local allocation is the size of the sub range.
@ranges_needed,
@range_begin,
@range_end,
@next_range_begin,
@next_range_end

return 0

No comments:

Post a Comment

Total Pageviews